static-markdown
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -19,14 +19,25 @@ #!/usr/bin/env node | ||
}).split('\n') | ||
let articleTitle = articleLines.shift() | ||
let articleMetadata = JSON.parse(articleLines.shift()) | ||
let articleFile = articleLines.join('\n') | ||
let article = marked(articleFile) | ||
let extentionParts = articlePath.split('.') | ||
let extension = extentionParts[extentionParts.length - 1] | ||
let article = '' | ||
if(extension === 'html') { | ||
article = articleFile | ||
} else { | ||
article = marked(articleFile) | ||
} | ||
let result = template({ | ||
article: article, | ||
title: articleTitle, | ||
metadata: articleMetadata, | ||
constants: constants | ||
}) | ||
let folder = articlePath.split('.md')[0].split('pages/')[1] | ||
if (articlePath.endsWith('index.md')) { | ||
let folder = articlePath.split('.' + extension)[0].split('pages/')[1] | ||
console.log(folder) | ||
if (articlePath.endsWith('index.' + extension)) { | ||
await fs.outputFile('public/'+folder+'.html', result) | ||
@@ -55,3 +66,3 @@ } else { | ||
let dirs = contents.filter(content => !content.includes('.')) | ||
let files = contents.filter(content => content.endsWith('.md')) | ||
let files = contents.filter(content => content.endsWith('.md') || content.endsWith('.html')) | ||
@@ -58,0 +69,0 @@ let paths = [] |
@@ -13,7 +13,7 @@ # How to use static-markdown | ||
2. Run `static-markdown` (the old `public` folder will be deleted) | ||
3. Use your site out of the `public` folder | ||
3. Your site is usable in the `public` folder | ||
## Example Site | ||
Check the `example-site` directory for an example or continue reading to see how to lay out a folder for `static-markdown`. | ||
Check the `example-site` directory for an example or continue reading to see how to use `static-markdown`. | ||
@@ -26,6 +26,6 @@ ## Project Directory Layout | ||
│ ├── whatever-folder | ||
│ │ ├── index.md | ||
│ │ ├── index.html | ||
│ │ └── whatever-post.md | ||
│ ├── index.md | ||
│ └── whatever-post.md | ||
│ └── whatever-post.html | ||
├── source | ||
@@ -35,3 +35,7 @@ │ ├── constants.json | ||
└── static | ||
└── * | ||
├── resource.png | ||
├── favicon.ico | ||
├── style.css | ||
└── folder | ||
└── ... | ||
``` | ||
@@ -41,6 +45,6 @@ | ||
Pages are in the form of: | ||
Markdown pages are in the form of: | ||
``` | ||
Title of page | ||
```markdown | ||
{ title: "Title of page", otherMetadata: "whatever" } | ||
# Markdown | ||
@@ -51,16 +55,25 @@ **More** markdown | ||
`index.md` is a special page, and refers to the root of the folder it is in. | ||
And HTML pages are in the form of: | ||
```html | ||
{ title: "Title of page", otherMetadata: "whatever" } | ||
<h1>HTML</h1> | ||
<b>More</b> HTML | ||
... | ||
``` | ||
`index.md` and `index.html` are special pages, and refer to the root of the folder it is in. | ||
With our previous example: | ||
``` | ||
└── pages | ||
├── whatever-folder | ||
│ ├── index.md | ||
│ └── whatever-post.md | ||
├── index.md | ||
└── whatever-post.md | ||
pages | ||
├── whatever-folder | ||
│ ├── index.html | ||
│ └── whatever-post.md | ||
├── index.md | ||
└── whatever-post.html | ||
``` | ||
Makes the following URLs | ||
Makes the following URLs: | ||
@@ -74,2 +87,4 @@ ``` | ||
Notice that `folder/index.html` is equivalent to `folder.html`. | ||
### Source Directory | ||
@@ -83,5 +98,5 @@ | ||
Here is an example `template.html` taken from `example-site/source/template.html`. | ||
Here is an example `template.html` taken from `example-site/source/template.html`: | ||
``` | ||
```html | ||
<!DOCTYPE html> | ||
@@ -94,3 +109,3 @@ <html lang="en"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>{{ title }}</title> | ||
<title>{{ metadata.title }}</title> | ||
<meta name="description" content="{{ constants.description }}"> | ||
@@ -122,16 +137,40 @@ | ||
The file can refer to local resources in the `static` folder just by using their path (not including `static/`). | ||
It also can use constants defined in `source/constants.json` using [handlebars](https://handlebarsjs.com/guide/). Here is an example of using a constant called description in the above file: | ||
It also can use constants defined in `source/constants.json` using [handlebars](https://handlebarsjs.com/guide/). Here is an example of using a constant called description in the above file. | ||
``` | ||
```html | ||
<meta name="description" content="{{ constants.description }}"> | ||
``` | ||
There are two special variables that can be used in templating: | ||
- `title` refers to the first line of the markdown page | ||
- `article` refers to the HTML output of the markdown (remember to use `{{{ article }}}` to get HTML instead of text) | ||
Similarly, JSON Metadata from the first line of each article can me used with `metadata.nameOfVariable`: | ||
```html | ||
<title>{{ metadata.title }}</title> | ||
``` | ||
There is one special variable that can be used in templating: | ||
- `article` refers to the HTML output of the markdown (remember to use `{{{ article }}}` to get the HTML output instead of text) | ||
### Static Directory | ||
Example Layout: | ||
``` | ||
static | ||
├── normalize.css | ||
├── standard-html-page.html | ||
└── logo.png | ||
``` | ||
This folder's contents are copied to the public folder so other files can reference them. | ||
It can also be used to have pages that do not go through `static-markdown`. | ||
You can reference them as if they were at the root of your site: | ||
```html | ||
<link rel="stylesheet" href="/normalize.css"> | ||
``` | ||
--- | ||
**That's it!** |
{ | ||
"name": "static-markdown", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Generate static sites using markdown", | ||
@@ -20,3 +20,5 @@ "main": "index.js", | ||
"static", | ||
"generator" | ||
"generator", | ||
"static-site", | ||
"static-site-generator" | ||
], | ||
@@ -23,0 +25,0 @@ "author": "Tripp Lyons", |
# static-markdown | ||
Generate static sites using markdown | ||
Generate static sites using markdown or just HTML ([Usage](docs/usage.md)) | ||
Screenshot: | ||
![A screenshot of static-markdown](example-screenshot.png) | ||
## Features | ||
## Usage | ||
- Markdown Conversion | ||
- Templating and Article Metadata | ||
- Nested Directories | ||
- And more to come (See [TODO.md](TODO.md)) | ||
See `docs/usage.md`. | ||
## Live Example | ||
I used it to make my website ([tripplyons.com](https://tripplyons.com/)). | ||
## Screenshot: | ||
![A screenshot of a static-markdown generated website](example-screenshot.png) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
60632
9
124
1
17