fix: build after titles migration
This commit is contained in:
parent
63454c28ab
commit
9266a786f2
2 changed files with 31 additions and 4 deletions
|
|
@ -3,10 +3,32 @@ import { rocketSearch } from '@rocket/search';
|
|||
import { rocketBlog } from '@rocket/blog';
|
||||
import { absoluteBaseUrlNetlify } from '@rocket/core/helpers';
|
||||
import { TitleMetaPlugin } from '@rocket/cli';
|
||||
import { adjustPluginOptions, removePlugin } from 'plugins-manager';
|
||||
import { adjustPluginOptions, addPlugin, removePlugin } from 'plugins-manager';
|
||||
import matter from 'gray-matter';
|
||||
import { mdjsSetupCode } from '@mdjs/core';
|
||||
import { copy } from '@web/rollup-plugin-copy';
|
||||
|
||||
/**
|
||||
* Plugin SocialMediaImagePlugin depends on titleMeta property
|
||||
* This property is wrapped into Proxy so it cannot be dynamically enhanced inside SocialMediaImagePlugin
|
||||
* It should really come from another plugin with "dataName" key eq to "titleMeta"
|
||||
*/
|
||||
class LionTitleMetaPlugin {
|
||||
static dataName = 'titleMeta';
|
||||
|
||||
async execute(data) {
|
||||
if (data.titleMeta) {
|
||||
return data.titleMeta;
|
||||
}
|
||||
const grayMatterFile = await matter.read(data.page.inputPath);
|
||||
if (grayMatterFile.data) {
|
||||
return grayMatterFile.data;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
presets: [rocketLaunch(), rocketSearch(), rocketBlog()],
|
||||
eleventy(eleventyConfig) {
|
||||
|
|
@ -33,5 +55,5 @@ export default {
|
|||
return config;
|
||||
}),
|
||||
],
|
||||
setupEleventyComputedConfig: [removePlugin(TitleMetaPlugin)]
|
||||
setupEleventyComputedConfig: [removePlugin(TitleMetaPlugin), addPlugin(LionTitleMetaPlugin)],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,13 +12,18 @@ for (const path of paths) {
|
|||
// save original values
|
||||
const { eleventyNavigation, ...rest } = grayMatterFile.data;
|
||||
// rocket values
|
||||
const { eleventyNavigation: rocketEleventyNavigation, ...rocketRest } = processContentWithTitle(grayMatterFile.content) || {};
|
||||
const { eleventyNavigation: rocketEleventyNavigation, ...rocketRest } =
|
||||
processContentWithTitle(grayMatterFile.content) || {};
|
||||
if (!rocketEleventyNavigation) {
|
||||
// not all pages need to change
|
||||
continue;
|
||||
}
|
||||
// merge them
|
||||
grayMatterFile.data = { ...rest, ...rocketRest, eleventyNavigation: { ...eleventyNavigation, ...rocketEleventyNavigation } };
|
||||
grayMatterFile.data = {
|
||||
...rest,
|
||||
...rocketRest,
|
||||
eleventyNavigation: { ...eleventyNavigation, ...rocketEleventyNavigation },
|
||||
};
|
||||
|
||||
await writeFile(grayMatterFile.path, matter.stringify(grayMatterFile));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue