-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asset pipeline and 404 generation now work
- Loading branch information
1 parent
500e5d7
commit 322a899
Showing
13 changed files
with
1,844 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const postcss = require('postcss'); | ||
const autoprefixer = require('autoprefixer'); | ||
const cssnano = require('cssnano'); | ||
const uglifyJS = require('uglify-es'); | ||
|
||
const filterFileList = require('../utils/filterFileList'); | ||
const { STATIC, BUILD } = require('../utils/constants'); | ||
|
||
module.exports = async function() { | ||
try { | ||
let assets = glob.sync(`${STATIC}/+(js|css)/**/*`); | ||
assets = filterFileList(assets, ['js', 'css']); | ||
|
||
for (const asset of assets) { | ||
let destination = path.join(BUILD, asset); | ||
let destinationDir = path.join(BUILD, path.dirname(asset)); | ||
|
||
if (!fs.existsSync(destinationDir)) { | ||
fs.mkdirpSync(destinationDir); | ||
} | ||
|
||
let contents = fs.readFileSync(asset).toString(); | ||
let extension = path.extname(asset); | ||
|
||
if (extension === '.js') { | ||
let result = uglifyJS.minify(contents); | ||
fs.writeFileSync(destination, result.code); | ||
} else if (extension === '.css') { | ||
let result = await postcss([cssnano, autoprefixer]) | ||
.process(contents, { from: asset, to: destination }); | ||
|
||
fs.writeFileSync(destination, result.css); | ||
} | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
const cleanFileList = require('../utils/cleanFileList'); | ||
const { STATIC, BUILD } = require('../utils/constants'); | ||
|
||
module.exports = async function() { | ||
try { | ||
let staticFiles = cleanFileList(fs.readdirSync(STATIC)); | ||
let minorStaticFiles = staticFiles.filter((path) => !['css', 'js'].includes(path)); | ||
|
||
for (const asset of minorStaticFiles) { | ||
fs.copySync( | ||
path.join(STATIC, asset), | ||
path.join(BUILD, STATIC, asset) | ||
); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const Liquid = require('liquid-node'); | ||
const engine = new Liquid.Engine(); | ||
|
||
const { LAYOUTS, BUILD } = require('../utils/constants'); | ||
|
||
// needed for `include` statements | ||
engine.registerFileSystem(new Liquid.LocalFileSystem(LAYOUTS)); | ||
|
||
module.exports = async function() { | ||
try { | ||
const pathTo404 = path.join(LAYOUTS, '404.html'); | ||
const destination = path.join(BUILD, '404.html'); | ||
|
||
const layout = fs.readFileSync(pathTo404).toString(); | ||
const rendered404 = await engine.parseAndRender(layout); | ||
|
||
fs.writeFileSync(destination, rendered404); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
9 changes: 6 additions & 3 deletions
9
lib/tasks/convertMarkdown.js → lib/tasks/generatePostsFromMarkdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function(files) { | ||
return files.filter((file) => { | ||
// Filters hidden files | ||
return !((/(^|\/)\.[^/.]/g).test(file)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
BUILD: 'build', | ||
PAGES: 'pages', | ||
STATIC: 'static', | ||
LAYOUTS: 'layouts' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
const path = require('path'); | ||
const cleanFileList = require('./cleanFileList'); | ||
|
||
// syntax sugar | ||
const extensions = { | ||
js: '.js', | ||
css: '.css', | ||
md: '.md' | ||
}; | ||
|
||
module.exports = function(files, extension) { | ||
return files.filter((file) => { | ||
// Checks if the file has the given extension, also filter hidden files | ||
return (path.extname(file) === `.${extension}`) && | ||
!((/(^|\/)\.[^/.]/g).test(file)); | ||
let cleanedFileList = cleanFileList(files); | ||
return cleanedFileList.filter((file) => { | ||
// Checks if the file has the given extension | ||
if (Array.isArray(extension)) { | ||
return Object.values(extensions).includes(path.extname(file)); | ||
} | ||
|
||
return (path.extname(file) === extensions[extension]); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.