Skip to content

Commit

Permalink
Merge branch 'feature-#1643' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Liane Hampe committed Jun 24, 2023
2 parents 25307a0 + e736df3 commit e14374f
Show file tree
Hide file tree
Showing 39 changed files with 3,137 additions and 3,359 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ If you prefer to install global packages using Yarn, run this command instead:

Alternately, you can use the `gulp` command that is installed by the project's dependencies.

$ $(npm bin)/gulp --version
$ npx --offline gulp --version

Now that you have the prerequisites installed, you can fetch and build the UI project.

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ If the layout looks for a partial, that partial must be located in the [.path]_p
The name of the partial is the stem of the file (e.g,. [.path]_partials/body.hbs_] becomes `body` and used as `> body`).
If the partial is inside a folder, the name of that folder is not used in the partial's name.
Additionally, any JavaScript files found in the [.path]_helpers_ directory are automatically registered as template helpers.
The name of the helper function matches the stem of the file (e.g., [.path]_heleprs/concat.js_ becomes `concat`).
The name of the helper function matches the stem of the file (e.g., [.path]_helpers/concat.js_ becomes `concat`).

Here's how a UI would be structured if it had layouts, partials, and helpers:

Expand Down
9 changes: 9 additions & 0 deletions docs/modules/ROOT/pages/templates.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ You can force this link to be shown by setting the environment variable `FORCE_S
If this property is set, the default UI shows an "Edit this Page" link that points to this URI (instead of the `page.editUrl` value) unless the `CI` environment variable is set (e.g., `CI=true`).
When the `CI` environment variable is set, the default UI ignores this property (since linking to a local file:// URI in a published site doesn't make any sense).

| page.origin
| Information about the content source from which the current page was taken.
Properties include url, reftype (since 3.1), refname, branch, tag, refhash (since 2.3), startPath, worktree, webUrl, fileUriPattern, editUrlPattern, private.

| page.origin.private
| This value will be `auth-required` if the git server requests authentication credentials, otherwise `auth-embedded` if credentials are embedded in the content source URL in the playbook, otherwise unset.
In the default UI, if this value is truthy, the "Edit this Page" link is not shown.
Expand Down Expand Up @@ -191,6 +195,11 @@ This value is _root-relative_ in the 404 page template, which is required for th

s| antoraVersion
| The version of Antora used to build the site (specifically the version of the @antora/page-composer package).

s| contentCatalog
| A proxy object around Antora's virtual content catalog, which provides access to components, component versions, pages, and resource files.
Exposes the following methods: `findBy`, `getById`, `getComponent`, `getComponentVersion`, `getComponents`, `getComponentsSortedBy`, `getFiles`, `getPages`, `getSiteStartPage`, `resolvePage`, and `resolveResource`.
*This object should only be used from a UI helper.*
|===

This model is likely to grow over time.
Expand Down
15 changes: 12 additions & 3 deletions gulp.d/tasks/build-preview-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ module.exports = (src, previewSrc, previewDest, sink = () => map()) => (done) =>
),
])
.then(([baseUiModel, { layouts }]) => {
const { asciidoc: { extensions = [] } = {} } = baseUiModel
const extensions = ((baseUiModel.asciidoc || {}).extensions || []).map((request) => {
ASCIIDOC_ATTRIBUTES[request.replace(/^@|\.js$/, '').replace(/[/]/g, '-') + '-loaded'] = ''
const extension = require(request)
extension.register.call(Asciidoctor.Extensions)
return extension
})
const asciidoc = { extensions }
for (const component of baseUiModel.site.components) {
for (const version of component.versions || []) version.asciidoc = asciidoc
}
baseUiModel = { ...baseUiModel, env: process.env }
delete baseUiModel.asciidoc
extensions.forEach((request) => require(request).register())
return [{ ...baseUiModel, env: process.env }, layouts]
return [baseUiModel, layouts]
})
.then(([baseUiModel, layouts]) =>
vfs
Expand Down
71 changes: 34 additions & 37 deletions gulp.d/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const autoprefixer = require('autoprefixer')
const browserify = require('browserify')
const buffer = require('vinyl-buffer')
const concat = require('gulp-concat')
const cssnano = require('cssnano')
const fs = require('fs-extra')
Expand Down Expand Up @@ -37,7 +36,7 @@ module.exports = (src, dest, preview) => () => {
}),
postcssUrl([
{
filter: new RegExp('^src/css/[~][^/]*(?:font|face)[^/]*/.*/files/.+[.](?:ttf|woff2?)$'),
filter: (asset) => new RegExp('^[~][^/]*(?:font|typeface)[^/]*/.*/files/.+[.](?:ttf|woff2?)$').test(asset.url),
url: (asset) => {
const relpath = asset.pathname.substr(1)
const abspath = require.resolve(relpath)
Expand All @@ -51,53 +50,25 @@ module.exports = (src, dest, preview) => () => {
postcssVar({ preserve: preview }),
// NOTE to make vars.css available to all top-level stylesheets, use the next line in place of the previous one
//postcssVar({ importFrom: path.join(src, 'css', 'vars.css'), preserve: preview }),
preview ? postcssCalc : () => {},
preview ? postcssCalc : () => {}, // cssnano already applies postcssCalc
autoprefixer,
preview
? () => {}
: (css, result) => cssnano({ preset: 'default' })(css, result).then(() => postcssPseudoElementFixer(css, result)),
]

return merge(
vfs.src('ui.yml', { ...opts, allowEmpty: true }),
vfs
.src('ui.yml', { ...opts, allowEmpty: true }),
vfs
.src('js/+([0-9])-*.js', { ...opts, sourcemaps })
.pipe(uglify())
.src('js/+([0-9])-*.js', { ...opts, read: false, sourcemaps })
.pipe(bundle(opts))
.pipe(uglify({ output: { comments: /^! / } }))
// NOTE concat already uses stat from newest combined file
.pipe(concat('js/site.js')),
vfs
.src('js/vendor/*([^.])?(.bundle).js', { ...opts, read: false })
.pipe(
// see https://gulpjs.org/recipes/browserify-multiple-destination.html
map((file, enc, next) => {
if (file.relative.endsWith('.bundle.js')) {
const mtimePromises = []
const bundlePath = file.path
browserify(file.relative, { basedir: src, detectGlobals: false })
.plugin('browser-pack-flat/plugin')
.on('file', (bundledPath) => {
if (bundledPath !== bundlePath) mtimePromises.push(fs.stat(bundledPath).then(({ mtime }) => mtime))
})
.bundle((bundleError, bundleBuffer) =>
Promise.all(mtimePromises).then((mtimes) => {
const newestMtime = mtimes.reduce((max, curr) => (curr > max ? curr : max), file.stat.mtime)
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
if (bundleBuffer !== undefined) file.contents = bundleBuffer
file.path = file.path.slice(0, file.path.length - 10) + '.js'
next(bundleError, file)
})
)
} else {
fs.readFile(file.path, 'UTF-8').then((contents) => {
file.contents = Buffer.from(contents)
next(null, file)
})
}
})
)
.pipe(buffer())
.pipe(uglify()),
.pipe(bundle(opts))
.pipe(uglify({ output: { comments: /^! / } })),
vfs
.src('js/vendor/*.min.js', opts)
.pipe(map((file, enc, next) => next(null, Object.assign(file, { extname: '' }, { extname: '.js' })))),
Expand Down Expand Up @@ -134,6 +105,32 @@ module.exports = (src, dest, preview) => () => {
).pipe(vfs.dest(dest, { sourcemaps: sourcemaps && '.' }))
}

function bundle ({ base: basedir, ext: bundleExt = '.bundle.js' }) {
return map((file, enc, next) => {
if (bundleExt && file.relative.endsWith(bundleExt)) {
const mtimePromises = []
const bundlePath = file.path
browserify(file.relative, { basedir, detectGlobals: false })
.plugin('browser-pack-flat/plugin')
.on('file', (bundledPath) => {
if (bundledPath !== bundlePath) mtimePromises.push(fs.stat(bundledPath).then(({ mtime }) => mtime))
})
.bundle((bundleError, bundleBuffer) =>
Promise.all(mtimePromises).then((mtimes) => {
const newestMtime = mtimes.reduce((max, curr) => (curr > max ? curr : max), file.stat.mtime)
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
if (bundleBuffer !== undefined) file.contents = bundleBuffer
next(bundleError, Object.assign(file, { path: file.path.slice(0, file.path.length - 10) + '.js' }))
})
)
return
}
fs.readFile(file.path, 'UTF-8').then((contents) => {
next(null, Object.assign(file, { contents: Buffer.from(contents) }))
})
})
}

function postcssPseudoElementFixer (css, result) {
css.walkRules(/(?:^|[^:]):(?:before|after)/, (rule) => {
rule.selector = rule.selectors.map((it) => it.replace(/(^|[^:]):(before|after)$/, '$1::$2')).join(',')
Expand Down
Loading

0 comments on commit e14374f

Please sign in to comment.