Skip to content

Commit

Permalink
add local build in cloud-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pengchengrun committed Dec 31, 2024
1 parent 077f80d commit 58e25cf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions antora-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
site:
title: "Cloud Doc Test"
start_page: "cloud4:overview:index.adoc"

content:
sources:
- url: .
branches: HEAD
start_paths: [modules/cloud4, modules/cloud]

output:
dir: ./build/site

ui:
bundle:
url: https://github.com/tigergraph/antora-ui/blob/main/build/ui-bundle.zip?raw=true
snapshot: true
38 changes: 38 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

const connect = require('gulp-connect')
const fs = require('fs')
const generator = require('@antora/site-generator-default')
const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
const { series, src, watch } = require('gulp')
const yaml = require('js-yaml')

const playbookFilename = 'antora-playbook.yml'
const playbook = yaml.load(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]
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) }
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cloud-docs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "antora generate --fetch antora-playbook.yml",
"dev": "gulp",
"serve": "http-server build/site -c-1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@antora/cli": "^3.1.1",
"@antora/site-generator-default": "^3.1.1",
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"gulp-connect": "^5.7.0",
"js-yaml": "^4.1.0"
}
}

0 comments on commit 58e25cf

Please sign in to comment.