|
4 | 4 |
|
5 | 5 | // BUILD.JS: This file is responsible for building static HTML pages
|
6 | 6 |
|
| 7 | +const fs = require('fs') |
| 8 | +const path = require('path') |
7 | 9 | const Metalsmith = require('metalsmith')
|
8 |
| -const autoprefixer = require('autoprefixer-stylus') |
9 | 10 | const collections = require('metalsmith-collections')
|
10 | 11 | const feed = require('metalsmith-feed')
|
11 | 12 | const discoverHelpers = require('metalsmith-discover-helpers')
|
12 | 13 | const discoverPartials = require('metalsmith-discover-partials')
|
13 | 14 | const layouts = require('metalsmith-layouts')
|
14 | 15 | const markdown = require('metalsmith-markdown')
|
15 | 16 | const prism = require('metalsmith-prism')
|
16 |
| -const stylus = require('metalsmith-stylus') |
17 | 17 | const permalinks = require('metalsmith-permalinks')
|
18 | 18 | const pagination = require('metalsmith-yearly-pagination')
|
19 | 19 | const defaultsDeep = require('lodash.defaultsdeep')
|
| 20 | +const autoprefixer = require('autoprefixer-stylus') |
20 | 21 | const marked = require('marked')
|
21 |
| -const path = require('path') |
22 |
| -const fs = require('fs') |
| 22 | +const stylus = require('stylus') |
23 | 23 | const ncp = require('ncp')
|
24 | 24 | const junk = require('junk')
|
25 | 25 |
|
26 | 26 | const navigation = require('./scripts/plugins/navigation')
|
27 |
| -const filterStylusPartials = require('./scripts/plugins/filter-stylus-partials') |
28 | 27 | const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headings')
|
29 | 28 | const loadVersions = require('./scripts/load-versions')
|
30 | 29 | const latestVersion = require('./scripts/helpers/latestversion')
|
@@ -238,33 +237,37 @@ function githubLinks (options) {
|
238 | 237 | }
|
239 | 238 |
|
240 | 239 | // This function builds the layouts folder for all the Stylus files.
|
241 |
| -function buildLayouts () { |
242 |
| - console.log('[metalsmith] build/layouts started') |
243 |
| - const labelForBuild = '[metalsmith] build/layouts finished' |
| 240 | +function buildCSS () { |
| 241 | + console.log('[stylus] static/css started') |
| 242 | + const labelForBuild = '[stylus] static/css finished' |
244 | 243 | console.time(labelForBuild)
|
245 | 244 |
|
246 | 245 | fs.mkdir(path.join(__dirname, 'build'), () => {
|
247 |
| - fs.mkdir(path.join(__dirname, 'build', 'layouts'), () => { |
248 |
| - const metalsmith = Metalsmith(__dirname) |
249 |
| - metalsmith |
250 |
| - // Sets the build source as /layouts/css. |
251 |
| - .source(path.join(__dirname, 'layouts', 'css')) |
252 |
| - // Deletes Stylus partials since they'll be included in the main CSS |
253 |
| - // file anyways. |
254 |
| - .use(filterStylusPartials()) |
255 |
| - .use(stylus({ |
256 |
| - compress: process.env.NODE_ENV !== 'development', |
257 |
| - paths: [path.join(__dirname, 'layouts', 'css')], |
258 |
| - use: [autoprefixer()] |
259 |
| - })) |
260 |
| - // Pipes the generated files into /build/static/css. |
261 |
| - .destination(path.join(__dirname, 'build/static/css')) |
| 246 | + fs.mkdir(path.join(__dirname, 'build/static'), () => { |
| 247 | + fs.mkdir(path.join(__dirname, 'build/static/css'), () => { |
| 248 | + fs.readFile(path.join(__dirname, 'layouts/css/styles.styl'), 'utf8', (err, data) => { |
| 249 | + if (err) { |
| 250 | + throw err |
| 251 | + } |
| 252 | + |
| 253 | + stylus(data) |
| 254 | + .set('compress', process.env.NODE_ENV !== 'development') |
| 255 | + .set('paths', [path.join(__dirname, 'layouts/css')]) |
| 256 | + .use(autoprefixer()) |
| 257 | + .render((error, css) => { |
| 258 | + if (error) { |
| 259 | + throw error |
| 260 | + } |
262 | 261 |
|
263 |
| - // This actually executes the build and stops the internal timer after |
264 |
| - // completion. |
265 |
| - metalsmith.build((err) => { |
266 |
| - if (err) { throw err } |
267 |
| - console.timeEnd(labelForBuild) |
| 262 | + fs.writeFile(path.join(__dirname, 'build/static/css/styles.css'), css, (err) => { |
| 263 | + if (err) { |
| 264 | + throw err |
| 265 | + } |
| 266 | + |
| 267 | + console.timeEnd(labelForBuild) |
| 268 | + }) |
| 269 | + }) |
| 270 | + }) |
268 | 271 | })
|
269 | 272 | })
|
270 | 273 | })
|
@@ -313,8 +316,8 @@ function fullBuild (opts) {
|
313 | 316 | const { selectedLocales, preserveLocale } = opts
|
314 | 317 | // Build static files.
|
315 | 318 | copyStatic()
|
316 |
| - // Build layouts |
317 |
| - buildLayouts() |
| 319 | + // Build CSS |
| 320 | + buildCSS() |
318 | 321 | getSource((err, source) => {
|
319 | 322 | if (err) { throw err }
|
320 | 323 |
|
|
0 commit comments