Skip to content

Commit

Permalink
support context plugins in SSR templating
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Mar 27, 2023
1 parent 4f0e45e commit 4f67e73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/cli/src/lib/templating-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ async function getCustomPageTemplatesFromPlugins(contextPlugins, templateName) {
}

async function getPageTemplate(filePath, context, template, contextPlugins = []) {
const isServing = process.env.__GWD_COMMAND__ === 'serve'; // eslint-disable-line no-underscore-dangle
const { templatesDir, userTemplatesDir, pagesDir, projectDirectory } = context;
const customPluginDefaultPageTemplates = isServing ? [] : await getCustomPageTemplatesFromPlugins(contextPlugins, 'page');
const customPluginPageTemplates = isServing ? [] : await getCustomPageTemplatesFromPlugins(contextPlugins, template);
const customPluginDefaultPageTemplates = await getCustomPageTemplatesFromPlugins(contextPlugins, 'page');
const customPluginPageTemplates = await getCustomPageTemplatesFromPlugins(contextPlugins, template);
const extension = filePath.split('.').pop();
const is404Page = filePath.startsWith('404') && extension === 'html';
const hasCustomTemplate = await checkResourceExists(new URL(`./${template}.html`, userTemplatesDir));
Expand Down Expand Up @@ -61,10 +60,9 @@ async function getPageTemplate(filePath, context, template, contextPlugins = [])

/* eslint-disable-next-line complexity */
async function getAppTemplate(pageTemplateContents, context, customImports = [], contextPlugins, enableHud, frontmatterTitle) {
const isServing = process.env.__GWD_COMMAND__ === 'serve'; // eslint-disable-line no-underscore-dangle
const { templatesDir, userTemplatesDir } = context;
const userAppTemplateUrl = new URL('./app.html', userTemplatesDir);
const customAppTemplatesFromPlugins = isServing ? [] : await getCustomPageTemplatesFromPlugins(contextPlugins, 'app');
const customAppTemplatesFromPlugins = await getCustomPageTemplatesFromPlugins(contextPlugins, 'app');
const hasCustomUserAppTemplate = await checkResourceExists(userAppTemplateUrl);
let appTemplateContents = customAppTemplatesFromPlugins.length > 0
? await fs.readFile(new URL('./app.html', customAppTemplatesFromPlugins[0]))
Expand Down
2 changes: 1 addition & 1 deletion www/pages/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ npm run serve
$ yarn serve
```

> _Note: You must have run `greenwood build` before running `greenwood serve`. Plugins are not available with `greenwood serve`, your application is built ahead of time atomically._
> _Note: You must have run `greenwood build` before running `greenwood serve`. Except for Context plugins, plugins are generally not available with `greenwood serve` as your application is built ahead of time._
### Sections

Expand Down

0 comments on commit 4f67e73

Please sign in to comment.