Created
September 3, 2020 13:58
-
-
Save synesthesia/b2d11154bebb29b1e670fc03c40692bd to your computer and use it in GitHub Desktop.
Gulp script to run local antora authoring preview
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
// see https://gitlab.com/antora/demo/docs-site/blob/watch-mode/gulpfile.js | |
// see https://gitlab.com/antora/antora/-/issues/329 | |
'use strict' | |
const connect = require('gulp-connect') | |
const fs = require('fs') | |
//const generator = require('@antora/site-generator-default') | |
const generator = require('antora-site-generator-lunr') | |
process.env['DOCSEARCH_ENABLED'] = true | |
process.env['DOCSEARCH_ENGINE'] = 'lunr' | |
const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {} | |
const { series, src, watch } = require('gulp') | |
const yaml = require('js-yaml') | |
const playbookFilename = 'local-antora-playbook.yml' | |
const playbook = yaml.safeLoad(fs.readFileSync(playbookFilename, 'utf8')) | |
const outputDir = (playbook.output || {}).dir || './build/site' | |
const serverConfig = { name: 'Preview Site', livereload, port: 5000, root: outputDir } | |
const antoraArgs = ['--playbook', playbookFilename, '--generator', 'antora-site-generator-lunr'] | |
const watchPatterns = playbook.content.sources.filter((source) => !source.url.includes(':')).reduce((accum, source) => { | |
accum.push(`${source.url}/${source.start_path ? source.start_path + '/' : ''}antora.yml`) | |
accum.push(`${source.url}/${source.start_path ? source.start_path + '/' : ''}**/*.adoc`) | |
return accum | |
}, []) | |
function generate (done) { | |
generator(antoraArgs, process.env) | |
.then(() => done()) | |
.catch((err) => { | |
console.log(err) | |
done() | |
}) | |
} | |
function serve (done) { | |
connect.server(serverConfig, function () { | |
this.server.on('close', done) | |
watch(watchPatterns, generate) | |
if (livereload) watch(this.root).on('change', (filepath) => src(filepath, { read: false }).pipe(livereload())) | |
}) | |
} | |
module.exports = { serve, generate, default: series(generate, serve) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment