Skip to content

Commit

Permalink
#21 Merge branch 'master' for gitlab.com:antora/antora-ui-default
Browse files Browse the repository at this point in the history
  • Loading branch information
countableSet authored Jan 5, 2023
2 parents 8faf0b4 + 19377f2 commit 89a55cf
Show file tree
Hide file tree
Showing 8 changed files with 3,493 additions and 3,859 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/create-helper.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module.exports = (tag, { data }) => {
const pageTags = asciidoc.attributes['page-tags']
return pageTags && pageTags.split(', ').includes(tag)
})
const { buildPageUiModel } = module.parent.require('@antora/page-composer/build-ui-model')
const { buildPageUiModel } = require.main.require('@antora/page-composer/build-ui-model')
return pages.map((page) => buildPageUiModel(site, page, contentCatalog))
}
----
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
69 changes: 33 additions & 36 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 @@ -49,52 +48,24 @@ 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 ? () => {} : cssnano({ preset: 'default' }),
preview ? () => {} : (css, result) => 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 @@ -159,6 +130,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 89a55cf

Please sign in to comment.