Skip to content

Antora 3 upgrade #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install Antora
run: npm i --no-optional --silent @antora/[email protected] @antora/[email protected]
- name: Install Lunr
run: npm i antora-lunr
- name: Install Lunr Site Generator
run: npm i antora-site-generator-lunr
node-version: '19'
- name: Install Antora and Lunr
run: npm i antora @antora/lunr-extension
- name: Run Antora
run: DOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr $(npm bin)/antora --fetch --generator antora-site-generator-lunr playbook.yml
run: npx antora playbook.yml
- name: Publish to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
Icon_
/build/site/
/node_modules/
/antora-ui-default-rp-src/node_modules/
/antora-ui-default-rp-src-antora-3/antora-ui-default-master/node_modules/
/antora-ui-default-rp-src/public/
13 changes: 3 additions & 10 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ The source files for this guide use asciidoc syntax and the project is configure

To build this guide locally, follow these steps:

. Follow the steps to install Antora that are described here: https://docs.antora.org/antora/2.0/install/install-antora/.
. Follow the steps to install Antora that are described here: https://docs.antora.org/antora/latest/install-and-run-quickstart/.
. Run `npm install -g asciidoc-link-check`
. Optional, to build with search enabled: Add the antora-lunr integration: https://github.com/Mogztter/antora-lunr by following the readme steps outlined in the *Generate an index file* section *only*. You do not need to enable search in the UI.

The command for building without search:
The command for building:
````
antora playbook.yml
````

The command for building with search enabled:

````
DOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr NODE_PATH="$(npm -g root)" antora --generator antora-site-generator-lunr playbook.yml
````

To preview

````
Expand All @@ -37,6 +30,6 @@ $ python -m SimpleHTTPServer

Antora is built on top of Asciidoctor. One of the main differences between Asciidoctor and Antora is that Antora requires a specfic directory structure. If you are new to Antora and asciidoc, the following references might be helpful:

* https://docs.antora.org/antora/2.0/
* https://docs.antora.org/antora/latest/
* https://asciidoctor.org/docs/
* http://asciidoc.org/
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"imports": "always-multiline",
"exports": "always-multiline"
}],
"no-restricted-properties": ["error", {
"property": "substr",
"message": "Use String#slice instead."
}],
"max-len": [1, 120, 2],
"spaced-comment": "off"
"spaced-comment": "off",
"radix": ["error", "always"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/node_modules/
/public/
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
image: node:10.14.2-stretch
stages: [setup, verify, deploy]
install:
stage: setup
cache:
paths:
- .cache/npm
script:
- &npm_install
npm install --quiet --no-progress --cache=.cache/npm
lint:
stage: verify
cache: &pull_cache
policy: pull
paths:
- .cache/npm
script:
- *npm_install
- node_modules/.bin/gulp lint
bundle-stable:
stage: deploy
only:
- master@antora/antora-ui-default
cache: *pull_cache
script:
- *npm_install
- node_modules/.bin/gulp bundle
artifacts:
paths:
- build/ui-bundle.zip
bundle-dev:
stage: deploy
except:
- master
cache: *pull_cache
script:
- *npm_install
- node_modules/.bin/gulp bundle
artifacts:
expire_in: 1 day # unless marked as keep from job page
paths:
- build/ui-bundle.zip
pages:
stage: deploy
only:
- master@antora/antora-ui-default
cache: *pull_cache
script:
- *npm_install
- node_modules/.bin/gulp preview:build
# FIXME figure out a way to avoid copying these files to preview site
- rm -rf public/_/{helpers,layouts,partials}
artifacts:
paths:
- public
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict'

module.exports = (numOfItems, { data }) => {
const { contentCatalog, site } = data.root
if (!contentCatalog) return
const rawPages = getDatedReleaseNotesRawPages(contentCatalog)
const pageUiModels = turnRawPagesIntoPageUiModels(site, rawPages, contentCatalog)
return getMostRecentlyUpdatedPages(pageUiModels, numOfItems)
}

let buildPageUiModel

function getDatedReleaseNotesRawPages (contentCatalog) {
return contentCatalog.getPages(({ asciidoc, out }) => {
if (!asciidoc || !out) return
return getReleaseNotesWithRevdate(asciidoc)
})
}

function getReleaseNotesWithRevdate (asciidoc) {
const attributes = asciidoc.attributes
return asciidoc.attributes && isReleaseNotes(attributes) && hasRevDate(attributes)
}

function isReleaseNotes (attributes) {
return attributes['page-component-name'] === 'release-notes'
}

function hasRevDate (attributes) {
return 'page-revdate' in attributes
}

function turnRawPagesIntoPageUiModels (site, pages, contentCatalog) {
buildPageUiModel ??= module.parent.require('@antora/page-composer/build-ui-model').buildPageUiModel
return pages
.map((page) => buildPageUiModel(site, page, contentCatalog))
.filter((page) => isValidDate(page.attributes?.revdate))
.sort(sortByRevDate)
}

function isValidDate (dateStr) {
return !isNaN(Date.parse(dateStr))
}

function sortByRevDate (a, b) {
return new Date(b.attributes.revdate) - new Date(a.attributes.revdate)
}

function getMostRecentlyUpdatedPages (pageUiModels, numOfItems) {
return getResultList(pageUiModels, Math.min(pageUiModels.length, numOfItems))
}

function getResultList (pageUiModels, maxNumberOfPages) {
const resultList = []
for (let i = 0; i < maxNumberOfPages; i++) {
const page = pageUiModels[i]
if (page.attributes?.revdate) resultList.push(getSelectedAttributes(page))
}
return resultList
}

function getSelectedAttributes (page) {
const latestVersion = getLatestVersion(page.contents.toString())
return {
latestVersionAnchor: latestVersion?.anchor,
latestVersionName: latestVersion?.innerText,
revdateWithoutYear: removeYear(page.attributes?.revdate),
title: cleanTitle(page.title),
url: page.url,
}
}

function getLatestVersion (contentsStr) {
const firstVersion = contentsStr.match(/<h2 id="([^"]+)">(.+?)<\/h2>/)
if (!firstVersion) return
const result = { anchor: firstVersion[1] }
if (isVersion(firstVersion[2])) result.innerText = firstVersion[2]
return result
}

function isVersion (versionText) {
return /^[0-9]+\.[0-9]+(?:\.[0-9]+)?/.test(versionText)
}

function removeYear (dateStr) {
if (!isValidDate(dateStr)) return
const dateObj = new Date(dateStr)
return `${dateObj.toLocaleString('default', { month: 'short' })} ${dateObj.getDate()}`
}

function cleanTitle (title) {
return title.split('Release Notes')[0].trim()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
* xref:prerequisites.adoc[]
* xref:set-up-project.adoc[]
* xref:build-preview-ui.adoc[]
* xref:development-workflow.adoc[]
* xref:templates.adoc[]
** xref:template-customization.adoc[]
** xref:create-helper.adoc[]
* xref:add-static-files.adoc[]
* xref:stylesheets.adoc[]
** xref:add-fonts.adoc[]
* xref:style-guide.adoc[]
** xref:inline-text-styles.adoc[]
** xref:image-styles.adoc[]
** xref:admonition-styles.adoc[]
** xref:code-blocks.adoc[]
** xref:list-styles.adoc[]
** xref:sidebar-styles.adoc[]
** xref:ui-macro-styles.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here are the steps involved.

. Use npm (or Yarn) to install the font files from a package (e.g., https://www.npmjs.com/package/typeface-open-sans[typeface-open-sans])

$ npm install --save typeface-open-sans
$ npm i --save typeface-open-sans

. In [.path]_src/css_, add a corresponding CSS file (e.g., [.path]_typeface-open-sans.css_)
. In that file, declare the font face:
Expand Down Expand Up @@ -64,7 +64,7 @@ TIP: If you're building on the default UI, you may instead want to define or upd

. Test the new font by previewing your UI:

$ gulp preview
$ npx gulp preview

If you see the new font, you've now successfully added it to your UI.
If you aren't sure, look for the https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Edit_fonts[All fonts on page] section in your browser's developer tools to see whether the font was loaded.
Expand Down Expand Up @@ -117,7 +117,7 @@ TIP: If you're building on the default UI, you may instead want to define or upd

. Test the new font by previewing your UI:

$ gulp preview
$ npx gulp preview

If you see the new font, you've now successfully added it to your UI.
If you aren't sure, look for the https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Edit_fonts[All fonts on page] section in your browser's developer tools to see whether the font was loaded.
Loading
Loading