Skip to content

Commit

Permalink
chore: Antora in charge of single-sourcing and validating content, ge…
Browse files Browse the repository at this point in the history
…nerating and validating the website (#2455)
  • Loading branch information
themr0c authored Sep 27, 2022
1 parent 059d9a5 commit 7360344
Show file tree
Hide file tree
Showing 37 changed files with 364 additions and 2,255 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ vendor
# Antora
.cache
node_modules/
build/plain-asciidoc
build/site
build/site.zip
build/site-unbranded
build/

# Keep Vale styles external
.vale/styles/CheDocs*
Expand Down
12 changes: 9 additions & 3 deletions antora-playbook-for-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ content:
edit_url: "https://github.com/eclipse-che/che-docs/edit/main/{path}"
antora:
extensions:
- require: "@antora/lunr-extension"
- id: search
require: '@antora/lunr-extension'
index_latest_only: true
snippet_length: 142
- id: collector
require: '@antora/collector-extension'
- id: htmltest
require: ./extensions/htmltest.js
- id: antora-to-plain-asciidoc
require: ./extensions/antora-to-plain-asciidoc.js
asciidoc:
sourcemap: true
output:
Expand All @@ -32,8 +39,7 @@ ui:
urls:
html_extension_style: indexify
redirect_facility: static
# latest_prerelease_version_segment: next
# latest_version_segment: stable
latest_prerelease_version_segment: next
latest_version_segment_strategy: replace
runtime:
cache_dir: ./.cache/antora
Expand Down
28 changes: 26 additions & 2 deletions antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ asciidoc:
prod-upstream: Eclipse Che
prod-url: "https://__<che_fqdn>__"
prod-ver-major: "7"
prod-ver-patch: "7.50.0"
prod-ver: "7.50"
prod-ver-patch: "7.53.0"
prod-ver: "7.53"
prod-workspace: che-ws
prod: Eclipse Che
prod2: Eclipse Che
Expand All @@ -108,3 +108,27 @@ asciidoc:
rh-os-devspaces: Red Hat OpenShift Dev Spaces
rh-os-local: Red Hat OpenShift Local
theia-endpoint-image: eclipse/che-theia-endpoint-runtime:next
ext:
collector:
- run:
command: ./tools/detect-unused-content.sh
- run:
command: ./tools/validate_language_changes.sh
- run:
command: ./tools/checluster_docs_gen.sh
scan:
base: modules/administration-guide/examples/checluster-properties
dir: build/collector/checluster-properties
files: checluster-properties.adoc
- run:
command: ./tools/environment_docs_gen.sh
scan:
base: modules/administration-guide/examples/che-server-properties
dir: build/collector/che-server-properties
files: system-variables.adoc
- run:
command: ./tools/create_architecture_diagrams.py
scan:
base: modules/administration-guide/images/architecture/
dir: build/collector/architecture-diagrams
files: '*.png'
21 changes: 21 additions & 0 deletions extensions/antora-to-plain-asciidoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2022 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//

// Validate the docs asynchronously.
'use strict'
module.exports.register = function () {
this.on('sitePublished', () => {
require('child_process').execFile('./tools/antora-to-plain-asciidoc.sh', (error, stdout, stderr) => {
if (error) {
console.log(stdout + stderr);
return;
}
console.log(stdout);
})
})
}
21 changes: 21 additions & 0 deletions extensions/htmltest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2022 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//

// Validate the docs asynchronously.
'use strict'
module.exports.register = function () {
this.on('sitePublished', () => {
require('child_process').execFile('htmltest', (error, stdout, stderr) => {
if (error) {
console.log(stdout + stderr);
return;
}
console.log(stdout);
})
})
}
130 changes: 21 additions & 109 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,119 +1,31 @@
'use strict'

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

const playbookFilename = 'antora-playbook-for-development.yml'
const playbook = yaml.load(fs.readFileSync(playbookFilename, 'utf8'))
const outputDir = (playbook.output || {}).dir || './build/site'
const serverConfig = { name: 'Preview Site', livereload, host: '0.0.0.0', port: 4000, root: outputDir }
const antoraArgs = ['--playbook', playbookFilename]
const watchPatterns = playbook.content.sources.filter((source) => !source.url.includes(':')).reduce((accum, source) => {
accum.push(`./antora.yml`)
accum.push(`./modules/**/*`)
return accum
}, [])
const gulp = require('gulp')

function generate(done) {
generator(antoraArgs, process.env)
.then(() => done())
.catch((err) => {
console.log(err)
done()
antora(['--playbook', 'antora-playbook-for-development.yml'], process.env)
.then(() => done())
.catch((err) => {
console.log(err)
done()
})
connect.reload()
}

async function serve(done) {
connect.server(serverConfig, function () {
this.server.on('close', done)
watch(watchPatterns, series(generate, testlang, testhtml, detect_unused_content, antora_to_plain_asciidoc))
if (livereload) watch(this.root).on('change', (filepath) => src(filepath, { read: false }).pipe(livereload()))
})
}

async function checluster_docs_gen() {
// Report script errors but don't make gulp fail.
try {
const { stdout, stderr } = await exec('tools/checluster_docs_gen.sh')
console.log(stdout);
console.error(stderr);
}
catch (error) {
console.log(error.stdout);
console.log(error.stderr);
return;
}
}

async function environment_docs_gen() {
// Report script errors but don't make gulp fail.
try {
const { stdout, stderr } = await exec('tools/environment_docs_gen.sh')
console.log(stdout, stderr);
}
catch (error) {
console.log(error.stdout, error.stderr);
return;
}
}

async function testhtml() {
// Report links errors but don't make gulp fail.
try {
const { stdout, stderr } = await exec('htmltest')
console.log(stdout, stderr);
}
catch (error) {
console.log(error.stdout, error.stderr);
return;
}
}

async function testlang() {
// Report language errors but don't make gulp fail.
try {
const { stdout, stderr } = await exec('./tools/validate_language_changes.sh')
console.log(stdout, stderr);
}
catch (error) {
console.log(error.stdout, error.stderr);
return;
}
}

async function detect_unused_content() {
// Report unused images but don't make gulp fail.
try {
const { stdout, stderr } = await exec('./tools/detect-unused-content.sh')
console.log(stdout, stderr);
}
catch (error) {
console.log(error.stdout, error.stderr);
return;
}
}

async function antora_to_plain_asciidoc() {
// Report unused images but don't make gulp fail.
try {
const { stdout, stderr } = await exec('./tools/antora-to-plain-asciidoc.sh')
console.log(stdout, stderr);
}
catch (error) {
console.log(error.stdout, error.stderr);
return;
}
}

exports.default = series(
parallel(checluster_docs_gen, environment_docs_gen),
generate,
serve,
parallel(testlang, testhtml, detect_unused_content, antora_to_plain_asciidoc)
connect.server({
name: 'Preview Site',
livereload: true,
host: '0.0.0.0',
port: 4000,
root: './build/site'
});
gulp.watch(['./modules/**/*'], generate)
}

exports.default = gulp.series(
generate,
serve,
);
Loading

0 comments on commit 7360344

Please sign in to comment.