Skip to content
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

feat: dynamic manifest path in layout plugin #33

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
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,21 +9,23 @@

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 type Meta = {name: string; content: string};

interface CommonOptions {
export interface CommonOptions {
title: string;
lang?: string;
isMobile?: boolean;
Expand Down Expand Up @@ -60,7 +60,7 @@
renderMeta(meta: Meta): string;
renderLink(link: Link): string;
}
export interface Plugin<Options = any, Name extends string = string> {

Check warning on line 63 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
name: Name;
apply: (params: {
options: Options | undefined;
Expand Down Expand Up @@ -98,7 +98,7 @@
? {[K in Name & string]: Options}
: {};

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void

Check warning on line 101 in src/types.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
? I
: never;

Expand Down
Loading