Updated to use siteOptions object

Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com>
This commit is contained in:
Andre Wanlin
2023-01-10 13:54:02 -06:00
committed by Renan Mendes Carvalho
parent 15b6eaf533
commit 943c245b6f
6 changed files with 18 additions and 15 deletions
@@ -106,7 +106,7 @@ export default async function generate(opts: OptionValues) {
logger,
etag: opts.etag,
...(process.env.LOG_LEVEL === 'debug' ? { logStream: stdout } : {}),
siteName: opts.siteName,
siteOptions: { name: opts.siteName },
});
logger.info('Done!');
@@ -186,7 +186,9 @@ export class DocsBuilder {
etag: newEtag,
logger: this.logger,
logStream: this.logStream,
siteName: this.entity.metadata.title ?? this.entity.metadata.name,
siteOptions: {
name: this.entity.metadata.title ?? this.entity.metadata.name,
},
});
// Remove Prepared directory since it is no longer needed.
@@ -518,13 +518,16 @@ describe('helpers', () => {
describe('getMkdocsYml', () => {
const inputDir = resolvePath(__filename, '../__fixtures__/');
const siteOptions = {
name: mockEntity.metadata.title,
};
it('returns expected contents when .yml file is present', async () => {
const key = path.join(inputDir, 'mkdocs.yml');
mockFs({ [key]: mkdocsYml });
const { path: mkdocsPath, content } = await getMkdocsYml(
inputDir,
mockEntity.metadata.title,
siteOptions,
);
expect(mkdocsPath).toBe(key);
@@ -536,7 +539,7 @@ describe('helpers', () => {
mockFs({ [key]: mkdocsYml });
const { path: mkdocsPath, content } = await getMkdocsYml(
inputDir,
mockEntity.metadata.title,
siteOptions,
);
expect(mkdocsPath).toBe(key);
expect(content).toBe(mkdocsYml.toString());
@@ -547,7 +550,7 @@ describe('helpers', () => {
mockFs({ [key]: mkdocsDefaultYml });
const { path: mkdocsPath, content } = await getMkdocsYml(
inputDir,
mockEntity.metadata.title,
siteOptions,
);
expect(mkdocsPath).toBe(key);
expect(content).toBe(mkdocsDefaultYml.toString());
@@ -555,9 +558,7 @@ describe('helpers', () => {
it('throws when neither .yml nor .yaml nor default file is present', async () => {
const invalidInputDir = resolvePath(__filename);
await expect(
getMkdocsYml(invalidInputDir, mockEntity.metadata.title),
).rejects.toThrow(
await expect(getMkdocsYml(invalidInputDir, siteOptions)).rejects.toThrow(
/Could not read MkDocs YAML config file mkdocs.yml or mkdocs.yaml or default for validation/,
);
});
@@ -159,7 +159,7 @@ export const MKDOCS_SCHEMA = DEFAULT_SCHEMA.extend([
*/
export const generateMkdocsYml = async (
inputDir: string,
siteName?: string,
siteOptions?: { name?: string },
) => {
try {
// TODO(awanlin): Use a provided default mkdocs.yml
@@ -168,7 +168,7 @@ export const generateMkdocsYml = async (
// minimum mkdocs.yml file
const mkdocsYmlPath = path.join(inputDir, 'mkdocs.yml');
const defaultSiteName = siteName ?? 'Table of Contents';
const defaultSiteName = siteOptions?.name ?? 'Table of Contents';
const defaultMkdocsContent =
`site_name: ${defaultSiteName}\n` +
'docs_dir: docs\n' +
@@ -193,7 +193,7 @@ export const generateMkdocsYml = async (
*/
export const getMkdocsYml = async (
inputDir: string,
siteName?: string,
siteOptions?: { name?: string },
): Promise<{ path: string; content: string }> => {
let mkdocsYmlPath: string;
let mkdocsYmlFileString: string;
@@ -217,7 +217,7 @@ export const getMkdocsYml = async (
}
// No mkdocs file, generate it
await generateMkdocsYml(inputDir, siteName);
await generateMkdocsYml(inputDir, siteOptions);
mkdocsYmlFileString = await fs.readFile(mkdocsYmlPath, 'utf8');
} catch (error) {
throw new ForwardedError(
@@ -96,13 +96,13 @@ export class TechdocsGenerator implements GeneratorBase {
etag,
logger: childLogger,
logStream,
siteName,
siteOptions,
} = options;
// Do some updates to mkdocs.yml before generating docs e.g. adding repo_url
const { path: mkdocsYmlPath, content } = await getMkdocsYml(
inputDir,
siteName,
siteOptions,
);
// validate the docs_dir first
@@ -62,7 +62,7 @@ export type GeneratorRunOptions = {
etag?: string;
logger: Logger;
logStream?: Writable;
siteName?: string;
siteOptions?: { name?: string };
};
/**