-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes gh-14
- Loading branch information
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
const fsp = require('node:fs/promises') | ||
const resolvedSearch = require.resolve('@springio/antora-extensions/static-pages/search') | ||
|
||
module.exports.register = function () { | ||
this.once('contentAggregated', async ({ contentAggregate }) => { | ||
for (const componentVersionBucket of contentAggregate) { | ||
const searchFile = { | ||
path: 'modules/ROOT/pages/search.adoc', | ||
contents: Buffer.from(await fsp.readFile(resolvedSearch, 'utf8')), | ||
src: { | ||
path: 'modules/ROOT/pages/search.adoc', | ||
basename: 'search.adoc', | ||
stem: 'search', | ||
extname: '.adoc', | ||
abspath: resolvedSearch, | ||
}, | ||
} | ||
componentVersionBucket.files.push(searchFile) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Search | ||
:page-article: search | ||
|
||
Search in all Spring Docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('./harness') | ||
const { name: packageName } = require('#package') | ||
const resolvedSearch = require.resolve('@springio/antora-extensions/static-pages/search') | ||
describe('static-page-extension', () => { | ||
const ext = require(packageName + '/static-page-extension') | ||
const createGeneratorContext = () => ({ | ||
messages: [], | ||
variables: {}, | ||
once (eventName, fn) { | ||
this[eventName] = fn | ||
}, | ||
on (eventName, fn) { | ||
this[eventName] = fn | ||
}, | ||
require, | ||
getLogger (name) { | ||
const messages = this.messages | ||
const appendMessage = function (message) { | ||
messages.push(message) | ||
} | ||
return { | ||
info: appendMessage, | ||
debug: appendMessage, | ||
} | ||
}, | ||
updateVariables (updates) { | ||
Object.assign(this.variables, updates) | ||
}, | ||
}) | ||
|
||
let contentAggregate | ||
let generatorContext | ||
let playbook | ||
|
||
beforeEach(async () => { | ||
generatorContext = createGeneratorContext() | ||
contentAggregate = [{ files: [] }] | ||
}) | ||
|
||
describe('bootstrap', () => { | ||
it('should be able to require extension', () => { | ||
expect(ext).to.be.instanceOf(Object) | ||
expect(ext.register).to.be.instanceOf(Function) | ||
}) | ||
|
||
it('should be able to call register function exported by extension', () => { | ||
ext.register.call(generatorContext, { config: {}, playbook }) | ||
expect(generatorContext.contentAggregated).to.be.instanceOf(Function) | ||
}) | ||
}) | ||
|
||
describe('contentAggregate', () => { | ||
it('adds file', async () => { | ||
ext.register.call(generatorContext, {}) | ||
await generatorContext.contentAggregated({ contentAggregate }) | ||
const search = contentAggregate[0].files[0] | ||
// convert contents to a String so it can be compared | ||
search.contents = search.contents.toString() | ||
expect(contentAggregate).to.eql([ | ||
{ | ||
files: [ | ||
{ | ||
contents: '= Search\n:page-article: search\n\nSearch in all Spring Docs', | ||
path: 'modules/ROOT/pages/search.adoc', | ||
src: { | ||
abspath: resolvedSearch, | ||
basename: 'search.adoc', | ||
extname: '.adoc', | ||
path: 'modules/ROOT/pages/search.adoc', | ||
stem: 'search', | ||
}, | ||
}, | ||
], | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |