From 26827157f93e0177ad7f74d4c9cf0d97fc748fd4 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Mon, 27 Feb 2023 16:05:39 -0600 Subject: [PATCH] Use publish-docsearch-config-extension Closes gh-12794 --- .github/actions/docsearch-config.json.hbs | 65 ------------------- antora-playbook.yml | 5 +- build.gradle | 2 +- .../extensions/publish-docsearch-config.js | 37 ----------- .../templates/per-branch-antora-playbook.yml | 2 +- 5 files changed, 5 insertions(+), 106 deletions(-) delete mode 100644 .github/actions/docsearch-config.json.hbs delete mode 100644 lib/antora/extensions/publish-docsearch-config.js diff --git a/.github/actions/docsearch-config.json.hbs b/.github/actions/docsearch-config.json.hbs deleted file mode 100644 index 94f73dd831..0000000000 --- a/.github/actions/docsearch-config.json.hbs +++ /dev/null @@ -1,65 +0,0 @@ -{ - "index_name": "spring-security-docs", - "start_urls": [ - {{#each latestVersions}} - { - "url": "{{{@root.site.url}}}/{{#if (eq ./activeVersionSegment '')}}(?:$|index.html$|[a-z].*){{else}}{{{./activeVersionSegment}}}/{{/if}}", - "extra_attributes": { - "component": "{{#if (eq ./name 'ROOT')}}security{{else}}{{{./name}}}{{/if}}", - "version": "{{{./version}}}", - "version_rank": {{#if (eq ./activeVersionSegment '')}}1{{else}}2{{/if}} - } - }{{#unless @last}},{{/unless}} - {{/each}} - ], - "sitemap_urls": [ - "{{{site.url}}}/sitemap.xml" - ], - "scrape_start_urls": true, - "stop_urls": [ - {{#each stopPages}} - "{{{@root.site.url}}}{{{./pub.url}}}"{{#unless @last}},{{/unless}} - {{/each}} - ], - "selectors": { - "default": { - "lvl0": { - "global": true, - "selector": ".nav-panel-explore .context .title, .nav-panel-explore .context .version" - }, - "lvl1": ".doc > h1.page", - "lvl2": ".doc .sect1 > h2:first-child", - "lvl3": ".doc .sect2 > h3:first-child", - "lvl4": ".doc .sect3 > h4:first-child", - "text": ".doc p, .doc dt, .doc td.content, .doc th.tableblock" - } - }, - "selectors_exclude": [ - "#section-summary" - ], - "min_indexed_level": 1, - "custom_settings": { - "advancedSyntax": true, - "attributesForFaceting": [ - "component", - "version" - ], - "attributesToRetrieve": [ - "anchor", - "content", - "hierarchy", - "url", - "component", - "version" - ], - "attributesToSnippet": [ - "content:25" - ], - "customRanking": [ - "desc(weight.page_rank)", - "asc(version_rank)", - "desc(weight.level)", - "asc(weight.position)" - ] - } -} diff --git a/antora-playbook.yml b/antora-playbook.yml index a03da3b8dd..31a164079c 100644 --- a/antora-playbook.yml +++ b/antora-playbook.yml @@ -10,8 +10,9 @@ antora: # uncomment this option to save the migrated content to the worktree #save_result: true unwrap_example_block: always - - require: ./lib/antora/extensions/publish-docsearch-config - template_path: ./.github/actions/docsearch-config.json.hbs + - require: '@springio/antora-extensions/publish-docsearch-config-extension' + index_name: 'spring-security-docs' + root_component_name: 'security' site: title: Spring Security url: https://docs.spring.io/spring-security/reference diff --git a/build.gradle b/build.gradle index 24b44fd3a2..11861561dd 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ antora { '@antora/collector-extension': '1.0.0-alpha.3', '@asciidoctor/tabs': '1.0.0-beta.3', '@opendevise/antora-release-line-extension': '1.0.0', - '@springio/antora-extensions': '1.0.0', + '@springio/antora-extensions': '1.1.0', '@springio/asciidoctor-extensions': '1.0.0-alpha.8', ] } diff --git a/lib/antora/extensions/publish-docsearch-config.js b/lib/antora/extensions/publish-docsearch-config.js deleted file mode 100644 index a40213e9b5..0000000000 --- a/lib/antora/extensions/publish-docsearch-config.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict' - -const fsp = require('node:fs/promises') -const ospath = require('node:path') - -/** - * An Antora extension that generates a config file that controls the behavior of the docsearch scraper. - * - * This extension generates a docsearch config file by evaluating a Handlebars template (e.g., - * .github/actions/docsearch-config.json.hbs). It then publishes the output file to the root of the site - * (docsearch-config.json). The docsearch scraper will retrieve for the config file from the published site. - * - * This extension will only add entries for the latest version in each release line. Additionally, if the page-archived - * or page-noindex attribute is defined in the document header of the page, that page will be excluded from the index. - */ -module.exports.register = function ({ config: { templatePath = './docsearch/config.json.hbs' } }) { - const expandPath = this.require('@antora/expand-path-helper') - const handlebars = this.require('handlebars').create() - handlebars.registerHelper('eq', (a, b) => a === b) - handlebars.registerHelper('and', (a, b) => a && b) - - this.on('beforePublish', async ({ playbook, contentCatalog, siteCatalog }) => { - templatePath = expandPath(templatePath, { dot: playbook.dir }) - const templateSrc = await fsp.readFile(templatePath, 'utf8') - const templateBasename = ospath.basename(templatePath) - const template = handlebars.compile(templateSrc, { noEscape: true, preventIndent: true, srcName: templateBasename }) - const latestVersions = contentCatalog.getComponentsSortedBy('name').reduce((accum, component) => { - component.versions.forEach((version) => version.versionSegment !== undefined && accum.push(version)) - return accum - }, []) - const stopPages = contentCatalog.getPages((page) => { - return page.out && ('page-archived' in page.asciidoc.attributes || 'page-noindex' in page.asciidoc.attributes) - }) - const compiled = template({ latestVersions, site: playbook.site, stopPages }) - siteCatalog.addFile({ contents: Buffer.from(compiled), out: { path: 'docsearch-config.json' } }) - }) -} diff --git a/lib/antora/templates/per-branch-antora-playbook.yml b/lib/antora/templates/per-branch-antora-playbook.yml index e3d3b401e1..b305a835b5 100644 --- a/lib/antora/templates/per-branch-antora-playbook.yml +++ b/lib/antora/templates/per-branch-antora-playbook.yml @@ -1,4 +1,4 @@ -# PACKAGES antora@3.2.0-alpha.2 @antora/atlas-extension:1.0.0-alpha.1 @antora/collector-extension@1.0.0-alpha.3 @springio/antora-extensions@1.0.0 @asciidoctor/tabs@1.0.0-beta.3 @opendevise/antora-release-line-extension@1.0.0 +# PACKAGES antora@3.2.0-alpha.2 @antora/atlas-extension:1.0.0-alpha.1 @antora/collector-extension@1.0.0-alpha.3 @springio/antora-extensions@1.1.0 @asciidoctor/tabs@1.0.0-beta.3 @opendevise/antora-release-line-extension@1.0.0 # # The purpose of this Antora playbook is to build the docs in the current branch. antora: