diff --git a/build.js b/build.js index da7caa3..094ac83 100644 --- a/build.js +++ b/build.js @@ -34,7 +34,7 @@ templateConfig = { // metalsmith var Metalsmith = require('metalsmith'); -// modules +// plugins var markdown = require('metalsmith-markdown'); var markdownPrecompiler = require('metalsmith-markdown-precompiler'); var collections = require('metalsmith-collections'); @@ -45,9 +45,16 @@ var discoverPartials = require('metalsmith-discover-partials'); var paths = require('metalsmith-paths'); var sitemap = require('metalsmith-sitemap'); var assets = require('metalsmith-assets'); +var wordcount = require("metalsmith-word-count"); + +// plugins dependend on devbuild- or production-build +var htmlmin = devBuild ? null : require('metalsmith-html-minifier'); var browsersync = devBuild ? require('metalsmith-browser-sync') : null; -moremeta = require(dir.lib + 'metalsmith-moremeta'); +// custom plugins +var setdate = require(dir.lib + 'metalsmith-setdate'); +var moremeta = require(dir.lib + 'metalsmith-moremeta'); +var debug = consoleLog ? require(dir.lib + 'metalsmith-debug') : null; console.log((devBuild ? 'Development' : 'Production'), 'build, version', pkg.version); @@ -59,13 +66,14 @@ var metalsmith = Metalsmith(__dirname) .destination(dir.dest) // build folder (build/) .metadata(siteMeta) // add meta data to every page .use(discoverPartials({ // needed for markdownPrecompiler - directory: 'partials', + directory: 'partials', pattern: /\.hbs$/ // original partials .html but exactly these parameters work })) // .use(json_to_files({ // source_path: './box/' // })) .use(paths()) + .use(setdate()) // set date on every page if not set in front-matter .use(collections({ // determine page collection/taxonomy page: { pattern: '**/index.*', @@ -104,6 +112,9 @@ var metalsmith = Metalsmith(__dirname) .use(permalinks({ // generate permalinks pattern: ':mainCollection/:title' })) + .use(wordcount({ // word count + raw: true + })) .use(moremeta()) // determine root paths and navigation, TODO check remove // .use(inplace({ // //engineOptions: {}, @@ -114,19 +125,20 @@ var metalsmith = Metalsmith(__dirname) pattern: `**/index.*`, default: 'page.hbs' })) - // .use(layouts({ - // //engineOptions: {}, - // pattern: `start/**`, - // default: 'article.hbs' - // })) - // .use(layouts({ - // //engineOptions: {}, - // pattern: `article/**`, - // default: 'article.hbs' - // })) - +// .use(layouts({ +// //engineOptions: {}, +// pattern: `start/**`, +// default: 'article.hbs' +// })) +// .use(layouts({ +// //engineOptions: {}, +// pattern: `article/**`, +// default: 'article.hbs' +// })) -// if (debug) metalsmith.use(debug()); // output page debugging information +if (htmlmin) metalsmith.use(htmlmin()); // minify production HTML + +if (debug) metalsmith.use(debug()); // output page debugging information if (browsersync) metalsmith.use(browsersync({ // start test server server: dir.dest, diff --git a/build/article/draft/index.html b/build/article/draft/index.html index 27862d6..653d9eb 100644 --- a/build/article/draft/index.html +++ b/build/article/draft/index.html @@ -1,113 +1 @@ - - - - -Draft article - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Draft article

- - - - - -

This is a draft article.

-

It will never appear in the site unless the publish front-matter is set to published or a date which has passed.

- - - - - - -
- - - - - - -
- -
- - - - - +Draft article - dashdev-website

Draft article

This is a draft article.

It will never appear in the site unless the publish front-matter is set to published or a date which has passed.

\ No newline at end of file diff --git a/build/article/future/index.html b/build/article/future/index.html index 4fb7c29..496a5b2 100644 --- a/build/article/future/index.html +++ b/build/article/future/index.html @@ -1,113 +1 @@ - - - - -Future publication - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Future publication

- - - - - -

This article will only appear if the site is built is run after 1 March, 2016.

- - - - - - -
- - - - - - -
- -
- - - - - +Future publication - dashdev-website

Future publication

This article will only appear if the site is built is run after 1 March, 2016.

\ No newline at end of file diff --git a/build/article/gotchas/index.html b/build/article/gotchas/index.html index d6e4def..2490b16 100644 --- a/build/article/gotchas/index.html +++ b/build/article/gotchas/index.html @@ -1,120 +1 @@ - - - - -Gotchas - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Gotchas

- - - - - -

Not everything is necessarily straight-forward in the Metalsmith world…

-

Incompatible plugins

-

Some plugins clash with another. For example, metalsmith-rootpath which calculates relative roots does not play nicely with metalsmith-permalinks which creates custom folder structures.

-

Note: lib/metalsmith-moremeta in this project sets a correct root variable whether permalinks are used or not.

-

Plugin order can be critical

-

One plugins may depend on another or conflict if placed the wrong way around. For example, the RSS-generating metalsmith-feed plugin must be called after metalsmith-layouts to ensure rss.xml is not generated within a page template.

-

Browsersync build issues

-

When Browsersync is running and files are edited, collections are re-parsed but the old data remains. This can cause menus and next/back links to be incorrect. To fix this, stop and restart the build.

- - - - - - -
- - - - - - -
- -
- - - - - +Gotchas - dashdev-website

Gotchas

Not everything is necessarily straight-forward in the Metalsmith world…

Incompatible plugins

Some plugins clash with another. For example, metalsmith-rootpath which calculates relative roots does not play nicely with metalsmith-permalinks which creates custom folder structures.

Note: lib/metalsmith-moremeta in this project sets a correct root variable whether permalinks are used or not.

Plugin order can be critical

One plugins may depend on another or conflict if placed the wrong way around. For example, the RSS-generating metalsmith-feed plugin must be called after metalsmith-layouts to ensure rss.xml is not generated within a page template.

Browsersync build issues

When Browsersync is running and files are edited, collections are re-parsed but the old data remains. This can cause menus and next/back links to be incorrect. To fix this, stop and restart the build.

\ No newline at end of file diff --git a/build/article/gulp/index.html b/build/article/gulp/index.html index a61ff93..df19709 100644 --- a/build/article/gulp/index.html +++ b/build/article/gulp/index.html @@ -1,65 +1,4 @@ - - - - -Gulp - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Gulp

- - - - - -

Metalsmith has plugins for CSS pre-processing with Sass, image minification, file concatenation, uglification and more. The build code will be familiar to anyone with Gulp experience.

-

Do you still need Gulp?

-

Metalsmith is often enough for simpler workflows. However, Gulp has a more extensive range of plugins and permits complex build activities such as linting and PostCSS processing with auto-prefixer.

-

Metalsmith can be used within any Gulp task, e.g.

-
var
+Gulp - dashdev-website

Gulp

Metalsmith has plugins for CSS pre-processing with Sass, image minification, file concatenation, uglification and more. The build code will be familiar to anyone with Gulp experience.

Do you still need Gulp?

Metalsmith is often enough for simpler workflows. However, Gulp has a more extensive range of plugins and permits complex build activities such as linting and PostCSS processing with auto-prefixer.

Metalsmith can be used within any Gulp task, e.g.

var
     gulp       = require('gulp'),
     metalsmith = require('metalsmith'),
     publish    = require('metalsmith-publish'),
@@ -78,60 +17,4 @@ gulp.task('html', function() {
             if (err) throw err;
         });
 
-});

Further Gulp tasks can then be added. Note .clean(false) ensures Metalsmith never wipes the build folder when other tasks are active.

-

There are a number of Gulp/Metalsmith integration plugins although they are rarely necessary.

- - - - - - -
- - - - - - -
- -
- -
- -

By dashdevs and featured on DashDevs.org

- -

Development build, version 1.0.0, article template

- -
- - - +});

Further Gulp tasks can then be added. Note .clean(false) ensures Metalsmith never wipes the build folder when other tasks are active.

There are a number of Gulp/Metalsmith integration plugins although they are rarely necessary.

\ No newline at end of file diff --git a/build/article/index.html b/build/article/index.html index 903693d..6e69407 100644 --- a/build/article/index.html +++ b/build/article/index.html @@ -1,150 +1 @@ - - - - -Articles - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- - - - - - - - -
- -
- - - - - +Articles - dashdev-website
\ No newline at end of file diff --git a/build/article/usage/index.html b/build/article/usage/index.html index 1ecd639..af1315c 100644 --- a/build/article/usage/index.html +++ b/build/article/usage/index.html @@ -1,120 +1 @@ - - - - -Usage options - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Usage options

- - - - - -

Metalsmith could be used to create any number of resources, including:

-
    -
  • a fast static website with minimal server-side requirements
  • -
  • technical documentation
  • -
  • an eBook
  • -
  • application prototypes
  • -
  • build tools or project scaffolding
  • -
-

The markdown files can be converted to other files types using plugins such as metalsmith-pandoc or metalsmith-pdf.

- - - - - - -
- - - - - - -
- -
- - - - - +Usage options - dashdev-website

Usage options

Metalsmith could be used to create any number of resources, including:

  • a fast static website with minimal server-side requirements
  • technical documentation
  • an eBook
  • application prototypes
  • build tools or project scaffolding

The markdown files can be converted to other files types using plugins such as metalsmith-pandoc or metalsmith-pdf.

\ No newline at end of file diff --git a/build/contact/index.html b/build/contact/index.html index 85c07ea..4dc9171 100644 --- a/build/contact/index.html +++ b/build/contact/index.html @@ -1,74 +1 @@ - - - - -Contact - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- - - - -
- -
- - - - - +Contact - dashdev-website
\ No newline at end of file diff --git a/build/index.html b/build/index.html index faac098..c3fedea 100644 --- a/build/index.html +++ b/build/index.html @@ -1,84 +1 @@ - - - - -dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- - -

Node.js

-

This is a static website generated using the Node.js-powered Metalsmith and various published and custom plugins.

-

This is a demonstration rather than a recommended way to build a static site. Your requirements will be different. Please use any part of the code as you wish.

-

Where could you use Metalsmith?

-

Metalsmith could be used to create:

-
    -
  • a fast static website with minimal server-side requirements
  • -
  • technical documentation
  • -
  • an eBook
  • -
  • application prototypes
  • -
  • build tools or project scaffolding
  • -
-

Get started…

- - -
- - -
- -
- - - - - +dashdev-website

Node.js

This is a static website generated using the Node.js-powered Metalsmith and various published and custom plugins.

This is a demonstration rather than a recommended way to build a static site. Your requirements will be different. Please use any part of the code as you wish.

Where could you use Metalsmith?

Metalsmith could be used to create:

  • a fast static website with minimal server-side requirements
  • technical documentation
  • an eBook
  • application prototypes
  • build tools or project scaffolding

Get started…

\ No newline at end of file diff --git a/build/sitemap.xml b/build/sitemap.xml index 4a08131..980521e 100644 --- a/build/sitemap.xml +++ b/build/sitemap.xml @@ -1,17 +1,17 @@ - http://127.0.0.1/ 1.0 - http://127.0.0.1/article/draft/ - http://127.0.0.1/article/future/ - http://127.0.0.1/article/gotchas/ - http://127.0.0.1/article/gulp/ - http://127.0.0.1/article/ 0.8 - http://127.0.0.1/article/usage/ - http://127.0.0.1/contact/ 0.7 - http://127.0.0.1/start/build/ 0.5 - http://127.0.0.1/start/ 0.9 - http://127.0.0.1/start/installation/ 0.5 - http://127.0.0.1/start/page-definitions/ 0.3 - http://127.0.0.1/start/plugins/ 0.3 - http://127.0.0.1/start/site-files/ 0.4 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/ 1.0 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/draft/ + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/future/ + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/gotchas/ + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/gulp/ + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/ 0.8 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/article/usage/ + https://rawgit.com/dashdev-suite/dashdev-website/master/build/contact/ 0.7 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/build/ 0.5 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/ 0.9 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/installation/ 0.5 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/page-definitions/ 0.3 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/plugins/ 0.3 + https://rawgit.com/dashdev-suite/dashdev-website/master/build/start/site-files/ 0.4 \ No newline at end of file diff --git a/build/start/build/index.html b/build/start/build/index.html index 18cf863..085e2b4 100644 --- a/build/start/build/index.html +++ b/build/start/build/index.html @@ -1,117 +1 @@ - - - - -Build - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Build

- - - - - -

To build and launch the site in a test server using Browsersync:

-
npm start

(Stop the server with Ctrl+C.)

-

To build the site for production and compress HTML files:

-
npm run production

The site is built in the /build folder.

-

Note you may want to change the siteMeta.domain and siteMeta.rootpath on lines 52 and 53 of ./build.js.

- - - - - - -
- - - - - - -
- -
- - - - - +Build - dashdev-website

Build

To build and launch the site in a test server using Browsersync:

npm start

(Stop the server with Ctrl+C.)

To build the site for production and compress HTML files:

npm run production

The site is built in the /build folder.

Note you may want to change the siteMeta.domain and siteMeta.rootpath on lines 52 and 53 of ./build.js.

\ No newline at end of file diff --git a/build/start/index.html b/build/start/index.html index 16059cf..648f39f 100644 --- a/build/start/index.html +++ b/build/start/index.html @@ -1,150 +1 @@ - - - - -Start - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- - - - - - - - -
- -
- - - - - +Start - dashdev-website
\ No newline at end of file diff --git a/build/start/installation/index.html b/build/start/installation/index.html index bc91bda..b97afae 100644 --- a/build/start/installation/index.html +++ b/build/start/installation/index.html @@ -1,117 +1 @@ - - - - -Installation - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Installation

- - - - - -

Please ensure Node.js and Git are installed on your system.

-

Download the demonstration code and switch to directory:

-

git clone git@github.com:dashdev-suite/dashdev-website.git - cd metalsmith-demo

-

Install dependencies:

-
npm install
- - - - - -
- - - - - - -
- -
- - - - - +Installation - dashdev-website

Installation

Please ensure Node.js and Git are installed on your system.

Download the demonstration code and switch to directory:

git clone git@github.com:dashdev-suite/dashdev-website.git cd metalsmith-demo

Install dependencies:

npm install
\ No newline at end of file diff --git a/build/start/page-definitions/index.html b/build/start/page-definitions/index.html index 8ce2b2b..a001df7 100644 --- a/build/start/page-definitions/index.html +++ b/build/start/page-definitions/index.html @@ -1,131 +1,8 @@ - - - - -Page definitions - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Page definitions

- - - - - -

Each sub-folder in src/html is a website section. Pages named index.md are the default page in section. File paths are translated to permalinks, e.g.

-
src/html/article/mypage.md

is rendered to:

-
build/article/mypage/index.html

Pages use YAML front-matter defined at the top. This can be referenced in templates or during the build process, e.g.

-
---
+Page definitions - dashdev-website

Page definitions

Each sub-folder in src/html is a website section. Pages named index.md are the default page in section. File paths are translated to permalinks, e.g.

src/html/article/mypage.md

is rendered to:

build/article/mypage/index.html

Pages use YAML front-matter defined at the top. This can be referenced in templates or during the build process, e.g.

---
 title: My page title
 description: A description of this page for meta tags and page lists.
 layout: page.html
 priority: 0.9
 publish: 2016-06-01
 date: 2016-06-01
----

All items are optional. Note:

-
    -
  • layout defaults to page.html unless metadata.layout is defined for the page collection (see the use(collections({ ... }) code in build.js).
  • -
  • priority is a number between 0 (low) and 1 (high) which is used to order menus and define XML sitemaps.
  • -
  • publish can be set draft, private or a future date to ensure it is not published until required.
  • -
  • date is the date of the article. If not set, a future publish date or the file creation date is used.
  • -
-

The page content is defined in markdown, HTML syntax or both below the front-matter section. The content can include Handlebars partials from the src/partials folder, e.g.

-
{{> partialname }}

where partialname is the partial filename without its .html extension.

- - - - - - -
- - - - - - -
- -
- -
- -

By dashdevs and featured on DashDevs.org

- -

Development build, version 1.0.0, article template

- -
- - - +---

All items are optional. Note:

  • layout defaults to page.html unless metadata.layout is defined for the page collection (see the use(collections({ ... }) code in build.js).
  • priority is a number between 0 (low) and 1 (high) which is used to order menus and define XML sitemaps.
  • publish can be set draft, private or a future date to ensure it is not published until required.
  • date is the date of the article. If not set, a future publish date or the file creation date is used.

The page content is defined in markdown, HTML syntax or both below the front-matter section. The content can include Handlebars partials from the src/partials folder, e.g.

{{> partialname }}

where partialname is the partial filename without its .html extension.

\ No newline at end of file diff --git a/build/start/plugins/index.html b/build/start/plugins/index.html index a952e85..fdbd23f 100644 --- a/build/start/plugins/index.html +++ b/build/start/plugins/index.html @@ -1,118 +1 @@ - - - - -Custom plugins - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Custom plugins

- - - - - -

The build.js file defines how the site is built using Metalsmith and various plugins.

-

Several custom plugins have been created specifically for this site:

-
    -
  • lib/metalsmith-debug.js: output debugging information to the console.
  • -
  • lib/metalsmith-setdate.js: ensure each page has a date. If a date is not defined in the page's front-matter, it is presumed to be the publish or file creation date.
  • -
  • lib/metalsmith-moremeta.js: applies further metadata to each page including the root folder, a default layout, primary and secondary navigation.
  • -
- - - - - - -
- - - - - - -
- -
- - - - - +Custom plugins - dashdev-website

Custom plugins

The build.js file defines how the site is built using Metalsmith and various plugins.

Several custom plugins have been created specifically for this site:

  • lib/metalsmith-debug.js: output debugging information to the console.
  • lib/metalsmith-setdate.js: ensure each page has a date. If a date is not defined in the page's front-matter, it is presumed to be the publish or file creation date.
  • lib/metalsmith-moremeta.js: applies further metadata to each page including the root folder, a default layout, primary and secondary navigation.
\ No newline at end of file diff --git a/build/start/site-files/index.html b/build/start/site-files/index.html index 4e43f20..7b3bc37 100644 --- a/build/start/site-files/index.html +++ b/build/start/site-files/index.html @@ -1,119 +1 @@ - - - - -Site files - dashdev-website - - - - - - - - - - - - - -
- -
- - - - - -
- -
- -
- -
- -
- -

Site files

- - - - - -

All files in the src folder can be edited:

-
    -
  • pages are created as markdown files in the src/html folder and sub-folders.
  • -
  • static assets such as CSS, JavaScript and image files are created in src/assets. These are copied without modification to build/.
  • -
  • page templates are defined in src/template.
  • -
  • reusable partials (chunks of HTML code) are declared in src/partials.
  • -
- - - - - - -
- - - - - - -
- -
- - - - - +Site files - dashdev-website

Site files

All files in the src folder can be edited:

  • pages are created as markdown files in the src/html folder and sub-folders.
  • static assets such as CSS, JavaScript and image files are created in src/assets. These are copied without modification to build/.
  • page templates are defined in src/template.
  • reusable partials (chunks of HTML code) are declared in src/partials.
\ No newline at end of file diff --git a/package.json b/package.json index a6bf2db..0ac9463 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "start": "node ./build.js", "production": "NODE_ENV=production node ./build.js", + "production-win": "set NODE_ENV=production & node ./build.js", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": {