Skip to content

Commit 2d82244

Browse files
authored
Merge pull request #90 from tigergraph/TCE-6160
TCE-6160 feat(docs): Support Cloud Docs Preview and local build;
2 parents d3942c9 + e1f71f0 commit 2d82244

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

README.adoc

+53-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,56 @@ This repository only contains the source files for the published documentation.
66
To view the published version, see link:https://docs.tigergraph.com/cloud[TigerGraph Cloud Documentation].
77

88
== Contribution
9-
For instructions on how to contribute to this repository, see link:https://github.com/tigergraph/doc-site/blob/main/contribution.adoc[Contribution guidelines].
9+
For instructions on how to contribute to this repository, see link:https://github.com/tigergraph/doc-site/blob/main/contribution.adoc[Contribution guidelines].
10+
11+
== Install dependencies
12+
To install dependencies, navigate to this repository and run:
13+
[,console]
14+
----
15+
npm install
16+
----
17+
18+
== Build site locally
19+
To build the site locally, run:
20+
[,console]
21+
----
22+
npm run build
23+
----
24+
The build will be available in the `build/` folder in the root directory.
25+
26+
IMPORTANT: Though the files are all in the `/build` folder, you won't be able to access other pages through the links if the files are not served by a server.
27+
To preview locally, you can <<Run a local server to view the build>>. If you really don't want to use a local server, edit the `antora-playbook.yml` file in your local environment, and change the `html_extension_style` under `urls` to `default`. This allows you to open the static files and have the links work.
28+
29+
=== Build from your local content source repository
30+
To have Antora build the site from your local content source repository, change the corresponding content source in the file `antora-playbook.yml` to point to your local git repository.
31+
32+
See https://docs.antora.org/antora/2.3/playbook/content-source-url/#local-urls[Use local content repositories] on Antora's documentation.
33+
34+
== Watch Mode
35+
36+
Watch Mode launches a local web server for preview. It will continue watching your local content source repository changes and rebuild the site.
37+
38+
[,console]
39+
----
40+
npm run dev
41+
----
42+
43+
You can access the web server at http://localhost:5000[http://localhost:5000].
44+
45+
== Run a local server to view the build
46+
47+
To open the build, run:
48+
[,console]
49+
----
50+
$ npm i -g http-server
51+
$ http-server build/site -c-1
52+
----
53+
Upon launching the command, the local address of the web server will be displayed in your terminal. You should see the following output in your terminal:
54+
55+
----
56+
Starting up http-server, serving build/site
57+
Available on:
58+
http://127.0.0.1:8080
59+
http://192.168.1.8:8080
60+
Hit CTRL-C to stop the server
61+
----

antora-playbook.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
site:
2+
title: "Cloud Doc Test"
3+
start_page: "cloud4:overview:index.adoc"
4+
5+
content:
6+
sources:
7+
- url: .
8+
branches: HEAD
9+
start_paths: [modules/cloud4, modules/cloud]
10+
11+
output:
12+
dir: ./build/site
13+
14+
ui:
15+
bundle:
16+
url: https://github.com/tigergraph/antora-ui/blob/main/build/ui-bundle.zip?raw=true
17+
snapshot: true

gulpfile.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
const connect = require('gulp-connect')
4+
const fs = require('fs')
5+
const generator = require('@antora/site-generator-default')
6+
const { reload: livereload } = process.env.LIVERELOAD === 'true' ? require('gulp-connect') : {}
7+
const { series, src, watch } = require('gulp')
8+
const yaml = require('js-yaml')
9+
10+
const playbookFilename = 'antora-playbook.yml'
11+
const playbook = yaml.load(fs.readFileSync(playbookFilename, 'utf8'))
12+
const outputDir = (playbook.output || {}).dir || './build/site'
13+
const serverConfig = { name: 'Preview Site', livereload, port: 5000, root: outputDir }
14+
const antoraArgs = ['--playbook', playbookFilename]
15+
const watchPatterns = playbook.content.sources.filter((source) => !source.url.includes(':')).reduce((accum, source) => {
16+
accum.push(`${source.url}/${source.start_path ? source.start_path + '/' : ''}antora.yml`)
17+
accum.push(`${source.url}/${source.start_path ? source.start_path + '/' : ''}**/*.adoc`)
18+
return accum
19+
}, [])
20+
21+
function generate (done) {
22+
generator(antoraArgs, process.env)
23+
.then(() => done())
24+
.catch((err) => {
25+
console.log(err)
26+
done()
27+
})
28+
}
29+
30+
function serve (done) {
31+
connect.server(serverConfig, function () {
32+
this.server.on('close', done)
33+
watch(watchPatterns, generate)
34+
if (livereload) watch(this.root).on('change', (filepath) => src(filepath, { read: false }).pipe(livereload()))
35+
})
36+
}
37+
38+
module.exports = { serve, generate, default: series(generate, serve) }

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "cloud-docs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "antora generate --fetch antora-playbook.yml",
8+
"dev": "gulp",
9+
"serve": "http-server build/site -c-1"
10+
},
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"@antora/cli": "^3.1.1",
15+
"@antora/site-generator-default": "^3.1.1",
16+
"gulp": "^4.0.2",
17+
"gulp-cli": "^2.3.0",
18+
"gulp-connect": "^5.7.0",
19+
"js-yaml": "^4.1.0"
20+
}
21+
}

0 commit comments

Comments
 (0)