Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Commit

Permalink
Version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RedKenrok committed Oct 15, 2018
1 parent 4b4b219 commit 54a993c
Show file tree
Hide file tree
Showing 25 changed files with 332 additions and 93 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog

## 1.0.3 (unreleased)
## 1.1.0 (2018-10-15)
### Added
- `rename.prettify` added to config, disabling this will not prettify urls of content files.
- `rename.underscore` added to config, enabling this will remove the first underscore of content files.
### Changed
- `debug` Changed from dependency to devDependency.
- Renamed `library/get/data.js` to `library/get/files.js`.
### Removed
- Assertions removed from `library/get/files.js` and `library/get/functions.js`.
### Fixed
- Optimized assigning excerpts to front matter.

## 1.0.3 (2018-10-11)
### Added
- `hoast-minify` added to process.
### Removed
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ hoastig(__dirname config, options);
* Default: `src`
* `sources`: The subdirectories to process files from, whereby the directories later in the list overwrite files in the directories before it.
* Type: `Array of strings`
* Default: `['']`
* Default: `null`
* `metadata`: Metadata given to the layouts.
* Type: `Object`
* Default: `{}`
Expand All @@ -110,6 +110,13 @@ hoastig(__dirname config, options);
* `js`: Options for [tenrser](https://github.com/terser-js/terser#minify-options).
* Type: `Object`
* Default: `{}`
* `rename`
* `prettify`: Whether to prettify the file paths for the web. For example going from `article.html` to `article/index.html`.
* Type: `Boolean`
* Default: `true`
* `underscore`: Whether to remove the underscore at the start of file names in the content directory.
* Type: `Boolean`
* Default: `false`
* `development`
* `host`: Address to use in a development build.
* Type: `String`
Expand All @@ -126,9 +133,7 @@ hoastig(__dirname config, options);
{
"destination": "dst",
"source": "src",
"sources": [
""
],
"sources": null,
"metadata": {},

"concurrency": Infinity,
Expand All @@ -140,6 +145,10 @@ hoastig(__dirname config, options);
},
"js": {}
},
"rename": {
"prettify": true,
"underscore": false
},

"development": {
"host": "localhost",
Expand All @@ -160,7 +169,7 @@ The destination directory is the directory relative to where the command is exec

### Source directory

The source directory is the directory relative to where the command is executed from and can be defined in the configuration file, by default this is set to `src`. A separate list of sources can be specified which are contained within the source directory. This list can be used to split parts of a site out in for instance a theme and content, by default this list is set to `[ "" ]`. The directories overwrite the previous one in the order they are provided in. The defaults result into taking the `src` directory as the root and only directory to build. Each source directory follows the following pattern of directories.
The source directory is the directory relative to where the command is executed from and can be defined in the configuration file, by default this is set to `src`. A separate list of sources can be specified which are contained within the source directory. This list can be used to split parts of a site out in for instance a theme and content, by default this list is set to `null`. The directories overwrite the previous one in the order they are provided in. The defaults result into taking the `src` directory as the root and only directory to build. Each source directory follows the following pattern of directories.

* `content`: Content files, each file will be transformed into a page. Files should have the `.hbs`, `.html`, or `.md` extension. Extension are eventually converted to `.html` if they are not already. Extension can also be chained so that a markdown file can include handlebar partials for instance. For example `page.hbs.md` will first be transformed from markdown to html, then it will be read as handlebars and transformed to html again, this time giving it the `.html` extension. Finally the resulting or pre-existing `.html` files will be minified.
* `decorators`: Handlebar decorators. Files should have the `.js` extension. The file should export a single handlebars decorator compatible function.
Expand Down
27 changes: 27 additions & 0 deletions examples/advanced/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Advanced example

> The example is made for hoastig version 1.1.0.
## Installation and usage

```
npm i --save
```

```
npm run build
```

## Explanation

### Underscore files

`src/site/content/_index.md` and `src/site/content/about/_index.hbs.md` both file names start with and underscore, however in the processed build the files will have been renamed to `dst/index.html` and `dst/about/index.html` with the underscore removed. This is done by setting the `rename.underscore` setting to true in the `hoastig.json` configuration. It is important to now that having both a `src/site/content/index.md` and `src/site/content/index.md` can lead to unpredictable results, as well as other files in the content directory starting with an underscore will be renamed too.

### Overriding files

`src/theme/static/icon.png` and `src/site/static/icon.png` both source directories contain a different icon with the same name. Since `theme` is first in the list it will be overridden by `site`, as a result the `B` icon will end up in the destination directory.

### Handlebars inside content files

`src/site/content/about/_index.hbs.md` the extension contains both `.md` and `.hbs` as a result the file will first be transformed from Markdown to HTML. Luckily it ignores any Handlebars code which means it can then be converted from Handlebars to HTML.
22 changes: 22 additions & 0 deletions examples/advanced/hoastig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"sources": [
"theme",
"site"
],
"metadata": {
"base_url": "http://localhost:8080",
"title": "Advanced example",

"icons": [
{
"href": "icons.png",
"size": 16,
"type": "image/png"
}
]
},

"rename": {
"underscore": true
}
}
10 changes: 10 additions & 0 deletions examples/advanced/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"scripts": {
"build": "node node_modules/hoastig/bin/hoastig",
"rebuild": "node node_modules/hoastig/bin/hoastig -r",
"devbuild": "node node_modules/hoastig/bin/hoastig -d -r"
},
"dependencies": {
"hoastig": "^1.1.1"
}
}
7 changes: 7 additions & 0 deletions examples/advanced/src/site/content/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Error 404!
---

# 404: Lorem ipsum, dolor sit amet!

Donec vulputate imperdiet aliquet. Fusce ac felis feugiat, sodales nisi id, vestibulum erat. Donec eget cursus mauris. Donec sit amet auctor tellus. Nam ac velit vitae libero facilisis suscipit. Phasellus mollis vestibulum hendrerit. Donec quis sem non tortor dignissim laoreet a et sem. Maecenas congue, velit nec ultrices consectetur, dolor justo scelerisque augue, sed varius orci quam nec quam. Aliquam erat volutpat. Sed auctor tristique nisl, ac egestas enim tincidunt ut. Morbi tincidunt enim non lobortis rhoncus.
14 changes: 14 additions & 0 deletions examples/advanced/src/site/content/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Advanced example

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus fermentum magna, at lacinia ligula vestibulum ut. Vestibulum est enim, hendrerit ut sem nec, dapibus elementum ex. Nam eros libero, blandit at erat non, aliquet sollicitudin eros. Quisque iaculis nibh placerat suscipit vulputate. Suspendisse mollis semper ultrices. In quis accumsan urna. Suspendisse sit amet est eu augue laoreet maximus id a elit. Cras nec viverra augue. Suspendisse potenti. Donec consequat est in risus vehicula, a dapibus justo bibendum. Proin rutrum placerat sodales. Donec suscipit nunc in maximus vulputate. Donec posuere orci quis ornare rutrum. Mauris mollis congue egestas.

* Vivamus imperdiet tellus a magna convallis, eu tempus ipsum malesuada.
* In quis nisi eget diam laoreet lacinia at a diam.
* In dapibus libero id consequat tempor.
* Phasellus ultrices nunc ut nibh condimentum pretium.
* Donec sagittis magna a massa tempus, eu sagittis dui volutpat.
* Sed ultrices turpis ut mauris placerat fringilla.

Phasellus hendrerit libero non leo tincidunt, eu vehicula tellus porttitor. Suspendisse potenti. Sed auctor orci vitae mauris semper facilisis. Nam dictum at mi ut tristique. Aenean eget posuere urna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat.

[Sed mollis.](/about)
25 changes: 25 additions & 0 deletions examples/advanced/src/site/content/about/_index.hbs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: About
---

# About

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ut velit sem. Duis in nisi ut erat iaculis bibendum a sed ex. Morbi vitae rutrum ex. Suspendisse potenti. Suspendisse sed efficitur leo, at posuere justo. Fusce sit amet sem non erat gravida sodales non sed nibh. Sed pharetra at purus sed dapibus. Integer sollicitudin malesuada ante, non tempor orci pulvinar sit amet. Nunc dictum erat dui, id lobortis dui efficitur nec. Nulla bibendum ornare justo, sit amet dapibus enim congue id. Aliquam erat volutpat. Vestibulum non neque eu turpis convallis luctus vel facilisis sem. Etiam eu pellentesque sapien.

Donec lobortis malesuada nisl eget facilisis. Aenean mauris risus, pharetra at suscipit non, maximus a ligula. Nunc tincidunt aliquam lacus, vel facilisis ex cursus nec. Curabitur tellus dui, egestas quis rutrum et, volutpat luctus tortor. Nullam quis diam odio. Ut ante mauris, suscipit vel finibus a, imperdiet sodales leo. Pellentesque tincidunt mauris lacus, at efficitur purus feugiat eu.

{{#> article }}
# Jane Doe

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla blandit tristique risus eu iaculis. Praesent cursus ultricies congue. Sed vestibulum est sed sollicitudin tincidunt. Vivamus ac velit vel diam eleifend rhoncus. Mauris eget lacinia est. Cras eget facilisis mi. Phasellus congue pellentesque tempor. Pellentesque vel gravida ipsum. Donec blandit enim erat. Nunc accumsan vel velit vitae tristique.

[Phasellus in.](/about/doejane)
{{/article }}

{{#> article }}
# John Doe

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla fermentum eget massa a bibendum. Sed mauris turpis, aliquam ac elit a, aliquet lacinia felis. Donec dui quam, lobortis luctus commodo eu, tincidunt eu sem. Nam velit ipsum, cursus sit amet finibus id, blandit vitae tellus. Nullam facilisis tempus risus nec auctor. Sed fringilla ut odio quis imperdiet. In hac habitasse platea dictumst. Aliquam nec interdum felis. Maecenas at rutrum arcu. Pellentesque et ante ligula. Pellentesque eget justo auctor, accumsan nisl id, efficitur felis. Morbi sodales maximus leo eu congue. Phasellus sed elit non purus pharetra egestas porta at mauris. Donec non egestas eros. Integer ac odio augue.

[Phasellus in.](/about/doejohn)
{{}}
9 changes: 9 additions & 0 deletions examples/advanced/src/site/content/about/doejane.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Jane Doe
---

# Jane Doe

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla blandit tristique risus eu iaculis. Praesent cursus ultricies congue. Sed vestibulum est sed sollicitudin tincidunt. Vivamus ac velit vel diam eleifend rhoncus. Mauris eget lacinia est. Cras eget facilisis mi. Phasellus congue pellentesque tempor. Pellentesque vel gravida ipsum. Donec blandit enim erat. Nunc accumsan vel velit vitae tristique.

Sed vel urna molestie, vehicula nisi at, efficitur dui. Pellentesque a sodales lacus. Suspendisse sit amet dui et leo suscipit facilisis ac vel erat. Quisque auctor eros vel magna suscipit, at vestibulum lorem consectetur. Sed fringilla id orci et tristique. Fusce urna erat, scelerisque id justo sit amet, laoreet finibus neque. Vivamus facilisis tellus sem, eu lacinia turpis congue sit amet. Fusce sagittis, magna quis pretium sollicitudin, velit lacus fermentum lorem, eget egestas metus tortor in massa.
9 changes: 9 additions & 0 deletions examples/advanced/src/site/content/about/doejohn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: John Doe
---

# John Doe

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla fermentum eget massa a bibendum. Sed mauris turpis, aliquam ac elit a, aliquet lacinia felis. Donec dui quam, lobortis luctus commodo eu, tincidunt eu sem. Nam velit ipsum, cursus sit amet finibus id, blandit vitae tellus. Nullam facilisis tempus risus nec auctor. Sed fringilla ut odio quis imperdiet. In hac habitasse platea dictumst. Aliquam nec interdum felis. Maecenas at rutrum arcu. Pellentesque et ante ligula. Pellentesque eget justo auctor, accumsan nisl id, efficitur felis. Morbi sodales maximus leo eu congue. Phasellus sed elit non purus pharetra egestas porta at mauris. Donec non egestas eros. Integer ac odio augue.

In suscipit lacus sed dignissim sagittis. Nunc volutpat rhoncus enim pretium pretium. Donec cursus pretium erat volutpat fermentum. Etiam lorem lacus, posuere et vulputate id, mollis mattis elit. Praesent viverra massa ac sapien vestibulum, id commodo libero egestas. Nunc auctor dui sit amet vehicula malesuada. Proin justo diam, hendrerit vitae felis id, interdum convallis turpis. Proin maximus erat vel nulla suscipit blandit. Donec tincidunt elit in nulla viverra gravida. Proin odio tortor, sodales ac metus sit amet, tempus dictum eros. Nam luctus leo vitae viverra eleifend. Morbi iaculis, lacus at finibus lacinia, risus augue viverra nulla, non pharetra metus justo sollicitudin ex. Pellentesque vel turpis quis diam porta hendrerit ac sit amet nibh. Nunc tincidunt ullamcorper lacus. Suspendisse turpis velit, fringilla eu massa eu, rhoncus suscipit sapien. Aenean sagittis auctor nisl in ultrices.
Binary file added examples/advanced/src/site/static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions examples/advanced/src/theme/layouts/base.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html dir="ltr" lang="en-GB">
<head>
<!-- meta -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
{{#with base_url }}
<base href="{{ this }}"/>
{{/with}}
{{#with title}}
<title>{{ this }}</title>
{{/with}}

<!-- Icons -->
{{#each icons }}
<link rel="icon" href="/{{ href }}" type="{{ type }}" sizes="{{ size }}x{{ size }}"/>
{{/each}}
</head>
<body>
<!-- Content -->
{{{ content }}}
</body>
</html>
3 changes: 3 additions & 0 deletions examples/advanced/src/theme/partials/article.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<article>
{{> @partial-block }}
</article>
Binary file added examples/advanced/src/theme/static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Basic example

For this example all settings will be left at their default value.

> The example is made for hoastig version 1.1.0.
## Installation and usage

```
npm i --save
```

```
npm run build
```
1 change: 1 addition & 0 deletions examples/basic/hoastig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 10 additions & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"scripts": {
"build": "node node_modules/hoastig/bin/hoastig",
"rebuild": "node node_modules/hoastig/bin/hoastig -r",
"devbuild": "node node_modules/hoastig/bin/hoastig -d -r"
},
"dependencies": {
"hoastig": "^1.1.1"
}
}
5 changes: 5 additions & 0 deletions examples/basic/src/content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Lorem ipsum dolor sit amet

Consectetur adipiscing elit. Nunc tellus neque, accumsan vitae mollis quis, efficitur a turpis. Nam id egestas ex. Pellentesque pulvinar condimentum diam, id iaculis sapien. Nulla hendrerit aliquam ligula at iaculis. In congue, mauris eget placerat placerat, augue ipsum porta lorem, ut ultricies velit nisl id massa. Phasellus gravida porta iaculis. Phasellus consectetur dapibus magna.

Mauris faucibus, sem vitae commodo mattis, purus diam fermentum risus, in dignissim est leo nec tortor. In luctus egestas eros et pharetra. Donec mattis dolor id justo varius ultrices. Vivamus id quam lobortis, fringilla erat a, vestibulum urna. Vestibulum vitae sagittis dolor. Etiam dignissim tempor nunc, vitae ultrices sem egestas at. Pellentesque vel convallis felis.
10 changes: 10 additions & 0 deletions examples/basic/src/layouts/base.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html dir="ltr" lang="en-GB">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
{{{ content }}}
</body>
</html>
1 change: 0 additions & 1 deletion examples/simple/hoastig.json

This file was deleted.

48 changes: 23 additions & 25 deletions library/get/data.js → library/get/files.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Node modules.
const assert = require(`assert`),
fs = require(`fs`),
const fs = require(`fs`),
path = require(`path`);

// If debug available require it.
const debug = require(`debug`)(`hoastig/get/data`);
let debug; try { debug = require(`debug`)(`hoastig/get/files`); } catch(error) { debug = function() {}; }

// Custom libraries.
const namePath = require(`../utils/namePath`),
Expand All @@ -18,31 +17,30 @@ const namePath = require(`../utils/namePath`),
* @param {Array of strings} extensions Array of file extensions formatted as `.html`.
* @returns Array of file paths of type string.
*/
const getData = async function(directory, sourceDirectories, subDirectory, extensions) {
// Validate arguments.
assert(typeof(directory) === `string`, `directory must be of type string.`);
assert(Array.isArray(sourceDirectories) && sourceDirectories.length > 0 && typeof(sourceDirectories[0] === `string`), `sourceDirectories must be an array of string.`);
if (subDirectory) {
assert(typeof(subDirectory) === `string`, `subDirectory must be of type string.`);
}
if (extensions) {
assert(Array.isArray(extensions) && extensions.length > 0 && typeof(extensions[0] === `string`), `extensions must be an array of string.`);
// Ensure extensions are lower case.
extensions = extensions.map(function(extension) {
return extension.toLowerCase();
});
}
const getFiles = async function(directory, sourceDirectories, subDirectory, extensions) {
debug(`Looking for custom files in directory '${directory}' in source directories '${sourceDirectories}' and in sub directory '${subDirectory}' with extensions '${extensions}'.`);

// Check if source directories, and construct path(s) where functions might be located.
const absolutePaths = [];
if (!sourceDirectories) {
absolutePaths.push(path.join(directory, subDirectory));
} else {
// Iterate through sources in reverse order.
for (let i = sourceDirectories.length - 1; i >= 0; i--) {
absolutePaths.push(path.join(directory, sourceDirectories[i], subDirectory));
}
}

debug(`Looking for custom files.`);
const files = {};
// Iterate through sources in reverse order.
for (let i = sourceDirectories.length - 1; i >= 0; i--) {
// Construct path where files might be located.
const absoluteDirectory = path.join(directory, sourceDirectories[i], subDirectory);
debug(`Looking for custom files in '${absoluteDirectory}'.`);
// Iterate through absolute paths.
const absolutePathsLength = absolutePaths.length;
for (let i = 0; i < absolutePathsLength; i++) {
const absolutePath = absolutePaths[i];
debug(`Looking for custom files in '${absolutePath}'.`);

// Go through directory and return paths relative to the given directory.
const filePaths = await walk(absoluteDirectory);
const filePaths = await walk(absolutePath);
if (!filePaths || filePaths.length <= 0) {
debug(`No files found in directory.`);
continue;
Expand All @@ -69,7 +67,7 @@ const getData = async function(directory, sourceDirectories, subDirectory, exten
}

// Get content from storage.
fs.readFile(path.join(absoluteDirectory, filePath), `utf8`, function(error, data) {
fs.readFile(path.join(absolutePath, filePath), `utf8`, function(error, data) {
if (error) {
debug(`File '${filePath}' ran into error when reading therefore ignored: ${error}`);
return resolve();
Expand Down Expand Up @@ -99,4 +97,4 @@ const getData = async function(directory, sourceDirectories, subDirectory, exten
return files;
};

module.exports = getData;
module.exports = getFiles;
Loading

0 comments on commit 54a993c

Please sign in to comment.