From: Dan Allen Date: Fri, 28 Dec 2018 23:22:19 +0000 (-0700) Subject: add support for writing preview pages in AsciiDoc X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=97a1d516e243585b2fa7afd50b84daf73488bd3d;p=working%2Feg-antora.git add support for writing preview pages in AsciiDoc --- diff --git a/gulpfile.js/tasks/build.js b/gulpfile.js/tasks/build.js index a2997e9..76e48d7 100644 --- a/gulpfile.js/tasks/build.js +++ b/gulpfile.js/tasks/build.js @@ -60,7 +60,12 @@ module.exports = (src, dest, preview) => () => { .pipe(uglify()), vfs.src('css/site.css', opts).pipe(postcss(postcssPlugins)), vfs.src('font/*.woff*(2)', opts), - vfs.src('img/**/*.{jpg,ico,png,svg}', opts).pipe(imagemin()), + vfs.src('img/**/*.{jpg,ico,png,svg}', opts).pipe(imagemin([ + imagemin.gifsicle(), + imagemin.jpegtran(), + imagemin.optipng(), + imagemin.svgo({ plugins: [{ removeViewBox: false }] }), + ])), vfs.src('helpers/*.js', opts), vfs.src('layouts/*.hbs', opts), vfs.src('partials/*.hbs', opts) diff --git a/gulpfile.js/tasks/preview-pages.js b/gulpfile.js/tasks/preview-pages.js index 9e704c2..cbf6fbb 100644 --- a/gulpfile.js/tasks/preview-pages.js +++ b/gulpfile.js/tasks/preview-pages.js @@ -1,31 +1,54 @@ 'use strict' +const asciidoctor = require('asciidoctor.js')() const fs = require('fs-extra') const handlebars = require('handlebars') const { obj: map } = require('through2') const merge = require('merge-stream') -const path = require('path') +const ospath = require('path') +const path = ospath.posix const requireFromString = require('require-from-string') const vfs = require('vinyl-fs') const yaml = require('js-yaml') -module.exports = (src, dest, siteSrc, siteDest, sink = () => map((_0, _1, next) => next()), layouts = {}) => () => +const ASCIIDOC_ATTRIBUTES = { + experimental: '', + icons: 'font', + sectanchors: '', + 'source-highlighter': 'highlight.js', +} + +module.exports = (src, dest, siteSrc, siteDest, sink = () => map(), layouts = {}) => () => Promise.all([ loadSampleUiModel(siteSrc), toPromise(merge(compileLayouts(src, layouts), registerPartials(src), registerHelpers(src))), - ]).then(([uiModel]) => + ]).then(([baseUiModel]) => Object.assign(baseUiModel, { env: process.env })).then((baseUiModel) => vfs - .src('**/*.html', { base: siteSrc, cwd: siteSrc }) + .src('**/*.adoc', { base: siteSrc, cwd: siteSrc }) .pipe( map((file, enc, next) => { - const compiledLayout = layouts[file.stem === '404' ? '404.hbs' : 'default.hbs'] - const siteRootPath = path.relative(path.dirname(file.path), path.resolve(siteSrc)) - uiModel.env = process.env + const siteRootPath = path.relative(ospath.dirname(file.path), ospath.resolve(siteSrc)) + const uiModel = Object.assign({}, baseUiModel) + uiModel.page = Object.assign({}, uiModel.page) uiModel.siteRootPath = siteRootPath uiModel.siteRootUrl = path.join(siteRootPath, 'index.html') uiModel.uiRootPath = path.join(siteRootPath, '_') - uiModel.page.contents = file.contents.toString().trim() - file.contents = Buffer.from(compiledLayout(uiModel)) + if (file.stem === '404') { + uiModel.page = { layout: '404', title: 'Page Not Found' } + } else { + const doc = asciidoctor.load(file.contents, { safe: 'safe', attributes: ASCIIDOC_ATTRIBUTES }) + uiModel.page.attributes = Object.entries(doc.getAttributes()) + .filter(([name, val]) => name.startsWith('page-')) + .reduce((accum, [name, val]) => { + accum[name.substr(5)] = val + return accum + }, {}) + uiModel.page.layout = doc.getAttribute('page-layout', 'default') + uiModel.page.title = doc.getDocumentTitle() + uiModel.page.contents = Buffer.from(doc.convert()) + } + file.extname = '.html' + file.contents = Buffer.from(layouts[uiModel.page.layout](uiModel)) next(null, file) }) ) @@ -34,7 +57,7 @@ module.exports = (src, dest, siteSrc, siteDest, sink = () => map((_0, _1, next) ) function loadSampleUiModel (siteSrc) { - return fs.readFile(path.join(siteSrc, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) + return fs.readFile(ospath.join(siteSrc, 'ui-model.yml'), 'utf8').then((contents) => yaml.safeLoad(contents)) } function registerPartials (src) { @@ -58,7 +81,7 @@ function registerHelpers (src) { function compileLayouts (src, layouts) { return vfs.src('layouts/*.hbs', { base: src, cwd: src }).pipe( map((file, enc, next) => { - layouts[file.basename] = handlebars.compile(file.contents.toString(), { preventIndent: true }) + layouts[file.stem] = handlebars.compile(file.contents.toString(), { preventIndent: true }) next() }) ) diff --git a/package.json b/package.json index 6b7749a..ab10fae 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "node": ">= 8.0.0" }, "devDependencies": { + "asciidoctor.js": "1.5.9", "autoprefixer": "~9.4", "browserify": "~16.2", "cssnano": "~4.1", diff --git a/preview-site-src/404.adoc b/preview-site-src/404.adoc new file mode 100644 index 0000000..e69de29 diff --git a/preview-site-src/404.html b/preview-site-src/404.html deleted file mode 100644 index e69de29..0000000 diff --git a/preview-site-src/index.adoc b/preview-site-src/index.adoc new file mode 100644 index 0000000..862e646 --- /dev/null +++ b/preview-site-src/index.adoc @@ -0,0 +1,202 @@ += Hardware and Software Requirements +Author Name +:idprefix: +:idseparator: - +:!example-caption: + +Platonem complectitur mediocritatem ea eos. +Ei nonumy deseruisse ius. +Mel id omnes verear. +Vis no velit audiam, sonet <> eum ne. +*Prompta eripuit* nec ad. + +== Cu solet + +Nominavi luptatum eos, an vim hinc philosophia intellegebat. +Lorem `expetenda` pertinacia et nec, wisi illud sonet qui ea. +Eum an doctus <>. +Eu mea inani iriure. + +[source,json] +---- +{ + "name": "module-name", + "version": "10.0.1", + "description": "An example module to illustrate the usage of package.json", + "author": "Author Name ", + "scripts": { + "test": "mocha", + "lint": "eslint" + } +} +---- + +.Example paragraph syntax +[source,asciidoc] +---- +.Optional title +[example] +This is an example paragraph. +---- + +.Optional title +[example] +This is an example paragraph. + +How about some code? + +[source,js] +---- +vfs + .src('js/vendor/*.js', { cwd: 'src', cwdbase: true, read: false }) + .pipe(tap((file) => { // <1> + file.contents = browserify(file.relative, { basedir: 'src', detectGlobals: false }).bundle() + })) + .pipe(buffer()) + .pipe(uglify()) + .pipe(gulp.dest('build')) +---- +<1> The tap function is used to wiretap the data in the pipe. + +Cum dicat #putant# ne. +Est in <> homero principes, meis deleniti mediocrem ad has. +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. + +.... +pom.xml +src/ + main/ + java/ + HelloWorld.java + test/ + java/ + HelloWorldTest.java +.... + +Select menu:File[Open Project] to open the project in your IDE. +Per ea btn:[Cancel] inimicus. +Ferri kbd:[F11] tacimates constituam sed ex, eu mea munere vituperata kbd:[Ctrl,T] constituam. + +.Sidebar +**** +Platonem complectitur mediocritatem ea eos. +Ei nonumy deseruisse ius. +Mel id omnes verear. + +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. +**** + +=== Liber recusabo + +No sea, at invenire voluptaria mnesarchum has. +Ex nam suas nemore dignissim, vel apeirian democritum et. +At ornatus splendide sed, phaedrum omittantur usu an, vix an noster voluptatibus. + +. potenti donec cubilia tincidunt +. etiam pulvinar inceptos velit quisque aptent himenaeos +. lacus volutpat semper porttitor aliquet ornare primis nulla enim + +Natum facilisis theophrastus an duo. +No sea, at invenire voluptaria mnesarchum has. + +* ultricies sociosqu tristique integer +* lacus volutpat semper porttitor aliquet ornare primis nulla enim +* etiam pulvinar inceptos velit quisque aptent himenaeos + +Eu sed antiopam gloriatur. +Ea mea agam graeci philosophia. + +* [ ] todo +* [x] done! + +Vis veri graeci legimus ad. + +sed:: +splendide sed + +mea:: +agam graeci + +At ornatus splendide sed. + +[#dependencies%autowidth] +|=== +|Library |Version + +|eslint +|^1.7.3 + +|eslint-config-gulp +|^2.0.0 + +|expect +|^1.20.2 + +|istanbul +|^0.4.3 + +|istanbul-coveralls +|^1.0.3 + +|jscs +|^2.3.5 +|=== + +Cum dicat putant ne. +Est in reque homero principes, meis deleniti mediocrem ad has. +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. + +[TIP] +This oughta do it! + +Cum dicat putant ne. +Est in reque homero principes, meis deleniti mediocrem ad has. +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. + +[NOTE] +==== +You've been down _this_ road before. +==== + +Cum dicat putant ne. +Est in reque homero principes, meis deleniti mediocrem ad has. +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. + +[WARNING] +==== +Watch out! +==== + +[CAUTION] +==== +[#inline]#I wouldn't try that if I were you.# +==== + +[IMPORTANT] +==== +Don't forget this step! +==== + +.Key Points to Remember +[TIP] +==== +If you installed the CLI and the default site generator globally, you can upgrade both of them with the same command. + + $ npm i -g @antora/cli @antora/site-generator-default +==== + +Nominavi luptatum eos, an vim hinc philosophia intellegebat. +Eu mea inani iriure. + +[discrete] +== Voluptua singulis + +Cum dicat putant ne. +Est in reque homero principes, meis deleniti mediocrem ad has. +Altera atomorum his ex, has cu elitr melius propriae. +Eos suscipit scaevola at. diff --git a/preview-site-src/index.html b/preview-site-src/index.html deleted file mode 100644 index 70b1a4b..0000000 --- a/preview-site-src/index.html +++ /dev/null @@ -1,335 +0,0 @@ -
-
-
-

Platonem complectitur mediocritatem ea eos. -Ei nonumy deseruisse ius. -Mel id omnes verear. -Vis no velit audiam, sonet praesent eum ne. -Prompta eripuit nec ad.

-
-
-
-
-

Cu solet

-
-
-

Nominavi luptatum eos, an vim hinc philosophia intellegebat. -Lorem expetenda pertinacia et nec, wisi illud sonet qui ea. -Eum an doctus maiestatis efficiantur. -Eu mea inani iriure.

-
-
-
-
{
-  "name": "module-name",
-  "version": "10.0.1",
-  "description": "An example module to illustrate the usage of package.json",
-  "author": "Author Name <author@example.com>",
-  "scripts": {
-    "test": "mocha",
-    "lint": "eslint"
-  }
-}
-
-
-
-
Example paragraph syntax
-
-
.Optional title
-[example]
-This is an example paragraph.
-
-
-
-
Optional title
-
-This is an example paragraph. -
-
-
-

How about some code?

-
-
-
-
vfs
-  .src('js/vendor/*.js', { cwd: 'src', cwdbase: true, read: false })
-  .pipe(tap((file) => { (1)
-    file.contents = browserify(file.relative, { basedir: 'src', detectGlobals: false }).bundle()
-  }))
-  .pipe(buffer())
-  .pipe(uglify())
-  .pipe(gulp.dest('build'))
-
-
-
- - - - - -
1The tap function is used to wiretap the data in the pipe.
-
-
-

Cum dicat putant ne. -Est in reque homero principes, meis deleniti mediocrem ad has. -Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
-
-
pom.xml
-src/
-  main/
-    java/
-      HelloWorld.java
-  test/
-    java/
-      HelloWorldTest.java
-
-
-
-

Select File  Open Project to open the project in your IDE. -Per ea Cancel inimicus. -Ferri F11 tacimates constituam sed ex, eu mea munere vituperata Ctrl+T constituam.

-
-
-
-
Sidebar
-
-

Platonem complectitur mediocritatem ea eos. -Ei nonumy deseruisse ius. -Mel id omnes verear.

-
-
-

Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
-
-
-

Liber recusabo

-
-

No sea, at invenire voluptaria mnesarchum has. -Ex nam suas nemore dignissim, vel apeirian democritum et. -At ornatus splendide sed, phaedrum omittantur usu an, vix an noster voluptatibus.

-
-
-
    -
  1. -

    potenti donec cubilia tincidunt

    -
  2. -
  3. -

    etiam pulvinar inceptos velit quisque aptent himenaeos

    -
  4. -
  5. -

    lacus volutpat semper porttitor aliquet ornare primis nulla enim

    -
  6. -
-
-
-

Natum facilisis theophrastus an duo. -No sea, at invenire voluptaria mnesarchum has.

-
-
-
    -
  • -

    ultricies sociosqu tristique integer

    -
  • -
  • -

    lacus volutpat semper porttitor aliquet ornare primis nulla enim

    -
  • -
  • -

    etiam pulvinar inceptos velit quisque aptent himenaeos

    -
  • -
-
-
-

Eu sed antiopam gloriatur. -Ea mea agam graeci philosophia.

-
-
-
    -
  • -

    todo

    -
  • -
  • -

    done!

    -
  • -
-
-
-

Vis veri graeci legimus ad.

-
-
-
-
sed
-
-

splendide sed

-
-
mea
-
-

agam graeci

-
-
-
-
-

At ornatus splendide sed.

-
- ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LibraryVersion

eslint

^1.7.3

eslint-config-gulp

^2.0.0

expect

^1.20.2

istanbul

^0.4.3

istanbul-coveralls

^1.0.3

jscs

^2.3.5

-
-

Cum dicat putant ne. -Est in reque homero principes, meis deleniti mediocrem ad has. -Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
- - - - - -
- - -This oughta do it! -
-
-
-

Cum dicat putant ne. -Est in reque homero principes, meis deleniti mediocrem ad has. -Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
- - - - - -
- - -
-

You’ve been down this road before.

-
-
-
-
-

Cum dicat putant ne. -Est in reque homero principes, meis deleniti mediocrem ad has. -Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
- - - - - -
- - -
-

Watch out!

-
-
-
-
- - - - - -
- - -
-

I wouldn’t try that if I were you.

-
-
-
-
- - - - - -
- - -
-

Don’t forget this step!

-
-
-
-
- - - - - -
- - -
Key Points to Remember
-
-

If you installed the CLI and the default site generator globally, you can upgrade both of them with the same command.

-
-
-
-
$ npm i -g @antora/cli @antora/site-generator-default
-
-
-
-
-
-

Nominavi luptatum eos, an vim hinc philosophia intellegebat. -Eu mea inani iriure.

-
-

Voluptua singulis

-
-

Cum dicat putant ne. -Est in reque homero principes, meis deleniti mediocrem ad has. -Altera atomorum his ex, has cu elitr melius propriae. -Eos suscipit scaevola at.

-
-
-
-
\ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 83424c4..48b77ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -463,6 +463,13 @@ asap@~2.0.6: resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY= +asciidoctor.js@1.5.9: + version "1.5.9" + resolved "https://registry.yarnpkg.com/asciidoctor.js/-/asciidoctor.js-1.5.9.tgz#28f8e8ee134b82627f0240e9b6a201b3d15d9524" + integrity sha512-k5JgwyV82TsiCpnYbDPReuHhzf/vRUt6NaZ+OGywkDDGeGG/CPfvN2Gd1MJ0iIZKDyuk4iJHOdY/2x1KBrWMzA== + dependencies: + opal-runtime "1.0.11" + asn1.js@^4.0.0: version "4.10.1" resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0" @@ -3015,6 +3022,17 @@ glob-watcher@^5.0.0: just-debounce "^1.0.0" object.defaults "^1.1.0" +glob@6.0.4: + version "6.0.4" + resolved "https://registry.yarnpkg.com/glob/-/glob-6.0.4.tgz#0f08860f6a155127b2fadd4f9ce24b1aab6e4d22" + integrity sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI= + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "2 || 3" + once "^1.3.0" + path-is-absolute "^1.0.0" + glob@^7.0.5, glob@^7.1.0, glob@^7.1.1, glob@^7.1.2: version "7.1.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" @@ -4661,7 +4679,7 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= -minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: +"minimatch@2 || 3", minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== @@ -5060,6 +5078,14 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" +opal-runtime@1.0.11: + version "1.0.11" + resolved "https://registry.yarnpkg.com/opal-runtime/-/opal-runtime-1.0.11.tgz#81fc2a2084ae5f25d5609eada375b756a3dab036" + integrity sha512-L+6pnRvXPlDtbamBRnJAnB9mEMXmsIQ/b+0r/2xJ5/n/nxheEkLo+Pm5QNQ08LEbEN9TI6/kedhIspqRRu6tXA== + dependencies: + glob "6.0.4" + xmlhttprequest "1.8.0" + optimist@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" @@ -7937,6 +7963,11 @@ x-is-string@^0.1.0: resolved "https://registry.yarnpkg.com/x-is-string/-/x-is-string-0.1.0.tgz#474b50865af3a49a9c4657f05acd145458f77d82" integrity sha1-R0tQhlrzpJqcRlfwWs0UVFj3fYI= +xmlhttprequest@1.8.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" + integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= + xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"