Skip to content

Commit

Permalink
feat: dynamic manifest path in layout plugin (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgaponov authored Feb 12, 2024
1 parent 482ed12 commit f3c5b97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/plugins/layout/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlescape from 'htmlescape';

import type {Plugin} from '../../types.js';
import type {CommonOptions, Plugin} from '../../types.js';

import {getAbsoluteUrl, getJSONContent} from './helpers.js';
import type {LayoutPluginOptions, Manifest} from './types.js';
Expand All @@ -9,20 +9,22 @@ export type {LayoutPluginOptions} from './types.js';

export interface LayoutInitOptions {
publicPath?: string;
manifest: string;
manifest: string | ((commonOptions: CommonOptions) => string);
}
export function createLayoutPlugin({
publicPath = '/build/',
manifest,
}: LayoutInitOptions): Plugin<LayoutPluginOptions, 'layout'> {
return {
name: 'layout',
apply({options, renderContent}) {
apply({options, renderContent, commonOptions}) {
if (!options) {
return;
}

const manifestFile: Manifest = getJSONContent(manifest, (err) => {
const manifestPath = typeof manifest === 'string' ? manifest : manifest(commonOptions);

const manifestFile: Manifest = getJSONContent(manifestPath, (err) => {
console.error('Unable to read manifest file', err);

Check warning on line 28 in src/plugins/layout/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Icon {

export type Meta = {name: string; content: string};

interface CommonOptions {
export interface CommonOptions {
title: string;
lang?: string;
isMobile?: boolean;
Expand Down

0 comments on commit f3c5b97

Please sign in to comment.