|
| 1 | +constpath=require('path'); |
| 2 | + |
| 3 | +constMetalsmith=require('metalsmith'); |
| 4 | + |
| 5 | +// plugins |
| 6 | +constmultiLanguage=require('metalsmith-multi-language'); |
| 7 | +constcollections=require('metalsmith-collections'); |
| 8 | +constpermalinks=require('metalsmith-permalinks'); |
| 9 | +constlinkcheck=require('metalsmith-linkcheck'); |
| 10 | +constdates=require('metalsmith-jekyll-dates'); |
| 11 | +constinPlace=require('metalsmith-in-place'); |
| 12 | +constlayouts=require('metalsmith-layouts'); |
| 13 | +constwatch=require('metalsmith-watch'); |
| 14 | +constwhen=require('metalsmith-if'); |
| 15 | + |
| 16 | +// custom plugins |
| 17 | +constchangeExt=require('./plugins/change-ext'); |
| 18 | +constmarkdown=require('./plugins/markdown'); |
| 19 | +consttoc=require('./plugins/toc'); |
| 20 | + |
| 21 | +constisDev=process.argv[2]==='--dev'; |
| 22 | +constcwd=path.resolve(__dirname,'..'); |
| 23 | + |
| 24 | +Metalsmith(cwd) |
| 25 | +// set globally available metadata |
| 26 | +.metadata({ |
| 27 | +sitename:'NativeScript-Vue', |
| 28 | +siteurl:'https://nativescript-vue.org/', |
| 29 | +description:'Build truly native apps using Vue.js' |
| 30 | +}) |
| 31 | +// look for files in the content directory |
| 32 | +.source('./content') |
| 33 | +// output files to the dist directory |
| 34 | +.destination('./dist') |
| 35 | +// clean the dist directory before building |
| 36 | +.clean(true) |
| 37 | +// ignore directories and files starting with an _ |
| 38 | +.ignore([ |
| 39 | +'_**/*', |
| 40 | +'**/_*', |
| 41 | +]) |
| 42 | +// watch the content dir when in dev mode (--dev) |
| 43 | +.use(when(isDev,watch({ |
| 44 | +paths:{ |
| 45 | +"${source}/**/*.{md, ejs}":true, |
| 46 | +"layouts/**/*":'**/*.md', |
| 47 | +} |
| 48 | +}))) |
| 49 | +// group certain files into collections |
| 50 | +.use(collections({ |
| 51 | +blog:'blog/*.md', |
| 52 | +docs:{ |
| 53 | +pattern:'docs/**/*.md', |
| 54 | +refer:false |
| 55 | +} |
| 56 | +})) |
| 57 | +// use jekyll style dates in the file names |
| 58 | +.use(dates()) |
| 59 | +// use multiple languages |
| 60 | +.use(multiLanguage({ |
| 61 | +default:'en', |
| 62 | +locales:['en','hu'] |
| 63 | +})) |
| 64 | +// render markdown using our own plugin around marked |
| 65 | +.use(markdown()) |
| 66 | +// add table of contents using our own plugin |
| 67 | +.use(toc()) |
| 68 | +// generate the final files to have pretty urls |
| 69 | +.use(permalinks({ |
| 70 | +relative:false, |
| 71 | + |
| 72 | +linksets:[ |
| 73 | +{ |
| 74 | +match:{collection:'blog'}, |
| 75 | +pattern:'blog/:date/:slug', |
| 76 | +}, |
| 77 | +{ |
| 78 | +match:{collection:'docs'}, |
| 79 | +pattern:':locale/docs/:title' |
| 80 | +} |
| 81 | +] |
| 82 | +})) |
| 83 | +// allow inPlace to process files |
| 84 | +.use(changeExt({ |
| 85 | +pattern:`*.html`, |
| 86 | +ext:'.ejs' |
| 87 | +})) |
| 88 | +// wrap content in handlebars layouts |
| 89 | +.use(layouts({ |
| 90 | +engine:'ejs', |
| 91 | +default:'default.ejs', |
| 92 | +partials:'layouts/_partials', |
| 93 | +partialExtension:'.ejs', |
| 94 | +rename:false |
| 95 | +})) |
| 96 | +// allow using template features inside the content directory |
| 97 | +.use(inPlace({ |
| 98 | +engineOptions:{ |
| 99 | +partials:'layouts/_partials', |
| 100 | +} |
| 101 | +})) |
| 102 | +// finally check if we have broken links |
| 103 | +.use(linkcheck({ |
| 104 | +failMissing:false |
| 105 | +})) |
| 106 | +// build the site |
| 107 | +.build((err)=>{ |
| 108 | +if(err){ |
| 109 | +console.log(err.toString()) |
| 110 | +} |
| 111 | +}); |