Skip to content

Commit

Permalink
chore(monorepo): merge in main
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderElias committed Feb 16, 2021
2 parents a1d21a5 + 7b79271 commit c3e4baa
Show file tree
Hide file tree
Showing 28 changed files with 104 additions and 93 deletions.
2 changes: 1 addition & 1 deletion demos/plugins/errorPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const errorPlugin = async (html, options) => {
};

const validator = async (config) => [];
registerPlugin('rendererHtml', 'errorPlugin', errorPlugin, validator);
registerPlugin('postProcessByHtml', 'errorPlugin', errorPlugin, validator);
2 changes: 1 addition & 1 deletion demos/plugins/tocPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ const tocPlugin = async (html, options) => {
};

const validator = async (config) => [];
registerPlugin('rendererHtml', 'toc', tocPlugin, validator);
registerPlugin('postProcessByHtml', 'toc', tocPlugin, validator);
12 changes: 6 additions & 6 deletions docs/Reference/plugins/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ When you want to [build your own plugin](/docs/Reference/plugins/custom-plugins/

`router` plugins teach Scully how to get the required data to be pre-render pages from the route-params.

#### [rendererHtml](/docs/Reference/plugins/types/render)
#### [postProcessByHtml](/docs/Reference/plugins/types/render)

`rendererHtml` plugins are used to transform the rendered HTML.
After the Angular application renders, the HTML content is passed to a `rendererHtml` plugin where it can be further modified.
`postProcessByHtml` plugins are used to transform the rendered HTML.
After the Angular application renders, the HTML content is passed to a `postProcessByHtml` plugin where it can be further modified.

#### [rendererDom](/docs/Reference/plugins/types/render)
#### [postProcessByDom](/docs/Reference/plugins/types/render)

`rendererDom` plugins are used to transform the rendered HTML.
After the Angular application renders, the HTML content is passed to a `rendererDom` plugin where it can be further modified.
`postProcessByDom` plugins are used to transform the rendered HTML.
After the Angular application renders, the HTML content is passed to a `postProcessByDom` plugin where it can be further modified.

### [Route process](/docs/Reference/plugins/types/route-process)

Expand Down
19 changes: 12 additions & 7 deletions docs/Reference/plugins/types/render.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: rendererHtml Plugin Type
title: postProcessByHtml Plugin Type
published: true
lang: en
position: 100
---

# `rendererHtml` Plugin Type
# `postProcessByHtml` Plugin Type

## Overview

Expand All @@ -16,7 +16,7 @@ A **render plugin** could be used to transform a page containing markdown into a

## Interface

A **`rendererHtml` plugin** is a function that returns a `Promise<String>`. The string in the promise must be the transformed
A **`postProcessByHtml` plugin** is a function that returns a `Promise<String>`. The string in the promise must be the transformed
HTML. The interface looks like this:

```typescript
Expand All @@ -28,9 +28,9 @@ function exampleContentPlugin(
}
```

## Making A `rendererHtml` Plugin
## Making A `postProcessByHtml` Plugin

The following **`rendererHtml` plugin** example adds a title to the header to a page if it does not find one.
The following **`postProcessByHtml` plugin** example adds a title to the header to a page if it does not find one.

```typescript
const { registerPlugin } = require('@scullyio/scully');
Expand All @@ -48,7 +48,12 @@ function defaultTitlePlugin(html, route) {

// DON NOT FORGET REGISTER THE PLUGIN
const validator = async (conf) => [];
registerPlugin('rendererHtml', 'defaultTitle', defaultTitlePlugin, validator);
registerPlugin(
'postProcessByHtml',
'defaultTitle',
defaultTitlePlugin,
validator
);

module.exports.defaultTitlePlugin = defaultTitlePlugin;
```
Expand All @@ -65,7 +70,7 @@ function smileEmojiPlugin(html, route) {
}
// DON NOT FORGET REGISTER THE PLUGIN
const validator = async (conf) => [];
registerPlugin('rendererHtml', 'smiles', smileEmojiPlugin, validator);
registerPlugin('postProcessByHtml', 'smiles', smileEmojiPlugin, validator);

module.exports.smileEmojiPlugin = smileEmojiPlugin;
```
9 changes: 7 additions & 2 deletions docs/Reference/plugins/types/render_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ function defaultTitlePlugin(html, route) {

// DON NOT FORGET REGISTER THE PLUGIN
const validator = async (conf) => [];
registerPlugin('rendererHtml', 'defaultTitle', defaultTitlePlugin, validator);
registerPlugin(
'postProcessByHtml',
'defaultTitle',
defaultTitlePlugin,
validator
);

module.exports.defaultTitlePlugin = defaultTitlePlugin;
```
Expand All @@ -65,7 +70,7 @@ function smileEmojiPlugin(html, route) {
}
// DON NOT FORGET REGISTER THE PLUGIN
const validator = async (conf) => [];
registerPlugin('rendererHtml', 'smiles', smileEmojiPlugin, validator);
registerPlugin('postProcessByHtml', 'smiles', smileEmojiPlugin, validator);

module.exports.smileEmojiPlugin = smileEmojiPlugin;
```
12 changes: 6 additions & 6 deletions docs/Reference/plugins/types/rendererDom.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: rendererDom Plugin Type
title: postProcessByDom Plugin Type
published: true
lang: en
position: 100
---

# `rendererDom` Plugin Type
# `postProcessByDom` Plugin Type

## Overview

Expand All @@ -16,7 +16,7 @@ A **render plugin** could be used to transform a page containing markdown into a

## Interface

A **`rendererDom` plugin** is a function that returns a `Promise<JSDOM>`. The string in the promise must be the transformed
A **`postProcessByDom` plugin** is a function that returns a `Promise<JSDOM>`. The string in the promise must be the transformed
HTML. The interface looks like this:

```typescript
Expand All @@ -28,8 +28,8 @@ function exampleContentPlugin(
}
```

## Difference with `rendererHtml` plugins
## Difference with `postProcessByHtml` plugins

While having exactly the same function as the `rendererHtml` the `rendererDom` plugins get, and shoudl return a JSDOM object. Those will be run before the `rendererHtml` are executed.
While having exactly the same function as the `postProcessByHtml` the `postProcessByDom` plugins get, and shoudl return a JSDOM object. Those will be run before the `postProcessByHtml` are executed.

## Sample of `rendererDom`
## Sample of `postProcessByDom`
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ setMyConfig(baseHrefRewritePlugin, {
href: '/',
});

registerPlugin('rendererHtml', baseHrefRewrite, baseHrefRewritePlugin);
registerPlugin('postProcessByHtml', baseHrefRewrite, baseHrefRewritePlugin);
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const docsLinkPlugin = async (dom: JSDOM, options: HandledRoute): Promise<JSDOM>
};

const validator = async (config) => [];
registerPlugin('rendererDom', docLink, docsLinkPlugin, validator);
registerPlugin('postProcessByDom', docLink, docsLinkPlugin, validator);

function dropEndingSlash(str: string) {
return str.endsWith('/') ? str.slice(0, -1) : str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export const googleAnalyticsPlugin = async (html: string): Promise<string> => {

const validator = async () => [];

registerPlugin('rendererHtml', GoogleAnalytics, googleAnalyticsPlugin, validator);
registerPlugin('postProcessByHtml', GoogleAnalytics, googleAnalyticsPlugin, validator);
2 changes: 1 addition & 1 deletion libs/plugins/logrocket/src/lib/plugins-logrocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const logrocketPlugin = async (html: string): Promise<string> => {

const validator = async () => [];

registerPlugin('rendererHtml', LogRocket, logrocketPlugin, validator);
registerPlugin('postProcessByHtml', LogRocket, logrocketPlugin, validator);
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ const copyToClipboardPlugin = async (dom: JSDOM, options: HandledRoute): Promise

const validator = async () => [];

registerPlugin('rendererDom', copyToClipboard, copyToClipboardPlugin, validator);
registerPlugin('postProcessByDom', copyToClipboard, copyToClipboardPlugin, validator);
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const criticalCssPlugin = async (incomingHtml: string, route: HandledRoute) => {
}
return incomingHtml;
};
registerPlugin('rendererHtml', criticalCSS, criticalCssPlugin);
registerPlugin('postProcessByHtml', criticalCSS, criticalCssPlugin);

function getStyleFiles(path) {
const entries = readdirSync(path, { withFileTypes: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FlashPrevention = 'ScullyPluginFlashPrevention';
const AppRootAttrsBlacklist = ['_nghost', 'ng-version'];
const MockRootAttrsBlacklist = [];

registerPlugin('rendererHtml', FlashPrevention, flashPreventionPlugin);
registerPlugin('postProcessByHtml', FlashPrevention, flashPreventionPlugin);
registerPlugin('router', FlashPrevention, async (ur) => [{ route: ur }]);

interface FlashPreventionPluginOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ const plugin = async (dom: JSDOM, route: HandledRoute) => {
return dom;
};

registerPlugin('rendererDom', removeScripts, plugin);
registerPlugin('postProcessByDom', removeScripts, plugin);
2 changes: 1 addition & 1 deletion libs/plugins/sentry/src/lib/plugins-sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export const sentryPlugin = async (html: string): Promise<string> => {

const validator = async () => [];

registerPlugin('rendererHtml', Sentry, sentryPlugin, validator);
registerPlugin('postProcessByHtml', Sentry, sentryPlugin, validator);
2 changes: 1 addition & 1 deletion libs/scully-schematics/src/add-plugin/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export interface Schema {
/**
* The type of plugin
*/
pluginType: 'router' | 'rendererHtml';
pluginType: 'router' | 'postProcessByHtml';
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const validator = async conf => [];
/**
registerPlugin(TypeOfPlugin, name of the plugin, plugin function, validator)
*/
registerPlugin('rendererHtml', '<%= camelize(name) %>', <%= camelize(name) %>, validator);
registerPlugin('postProcessByHtml', '<%= camelize(name) %>', <%= camelize(name) %>, validator);
2 changes: 1 addition & 1 deletion libs/scully-schematics/src/plugin-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const myFunctionPlugin = async (html: string): Promise<string> => {
const validator = async () => [];
registerPlugin('rendererHtml', myPlugin, myFunctionPlugin, validator);
registerPlugin('postProcessByHtml', myPlugin, myFunctionPlugin, validator);
`
);
};
Expand Down
32 changes: 16 additions & 16 deletions libs/scully/src/lib/pluginManagement/Plugin.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type RoutePlugin = {
(route?: string, config?: any): Promise<HandledRoute[]>;
[configValidator]?: ConfigValidator | undefined;
};
export type rendererDomPlugin = (dom?: JSDOM, route?: HandledRoute) => Promise<JSDOM>;
export type RenderPlugin = (html?: string, route?: HandledRoute) => Promise<string>;
export type postProcessByDomPlugin = (dom?: JSDOM, route?: HandledRoute) => Promise<JSDOM>;
export type postProcessByHtmlPlugin = (html?: string, route?: HandledRoute) => Promise<string>;
export type RouteProcess = { (routes?: HandledRoute[]): Promise<HandledRoute[]>; [routeProcessPriority]?: number };
export type RouteDiscoveryPlugin = (routes?: HandledRoute[]) => Promise<void>;
export type AllDonePlugin = (routes?: HandledRoute[]) => Promise<void>;
Expand All @@ -20,28 +20,28 @@ export type ScullySystemPlugin = (...args: unknown[]) => Promise<unknown>;
export type EnterprisePlugin = (...args: unknown[]) => Promise<unknown>;

export interface Plugins {
render: { [name: string]: RenderPlugin };
rendererHtml: { [name: string]: RenderPlugin };
rendererDom: { [name: string]: rendererDomPlugin };
router: { [name: string]: RoutePlugin };
routeProcess: { [name: string]: RouteProcess };
routeDiscoveryDone: { [name: string]: RouteDiscoveryPlugin };
allDone: { [name: string]: AllDonePlugin };
enterprise: { [pluginSymbol: string]: (...args: unknown[]) => unknown };
fileHandler: { [fileExtension: string]: FilePlugin };
postProcessByDom: { [name: string]: postProcessByDomPlugin };
postProcessByHtml: { [name: string]: postProcessByHtmlPlugin };
render: { [name: string]: postProcessByHtmlPlugin };
routeDiscoveryDone: { [name: string]: RouteDiscoveryPlugin };
routeProcess: { [name: string]: RouteProcess };
router: { [name: string]: RoutePlugin };
scullySystem: { [pluginSymbol: string]: (...args: unknown[]) => unknown };
enterprise: { [pluginSymbol: string]: (...args: unknown[]) => unknown };
}
export interface PluginFuncs {
rendererDom: rendererDomPlugin;
rendererHtml: RenderPlugin;
render: RenderPlugin;
router: RoutePlugin;
routeProcess: RouteProcess;
routeDiscoveryDone: RouteDiscoveryPlugin;
allDone: AllDonePlugin;
enterprise: (...args: unknown[]) => unknown;
fileHandler: FilePlugin;
postProcessByDom: postProcessByDomPlugin;
postProcessByHtml: postProcessByHtmlPlugin;
render: postProcessByHtmlPlugin;
routeDiscoveryDone: RouteDiscoveryPlugin;
routeProcess: RouteProcess;
router: RoutePlugin;
scullySystem: (...args: unknown[]) => unknown;
enterprise: (...args: unknown[]) => unknown;
}
export type PluginTypes = keyof Plugins;

Expand Down
37 changes: 19 additions & 18 deletions libs/scully/src/lib/pluginManagement/pluginRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@ export const accessPluginDirectly = Symbol('accessPluginDirectly');
export const routeProcessPriority = Symbol('routeProcessPriority');
export const scullySystem = `scullySystem`;

const rendererHtml = {};
const postProcessByHtml = {};

export const plugins: Plugins = {
render: rendererHtml,
rendererHtml,
rendererDom: {},
router: {},
fileHandler: {},
routeProcess: {},
routeDiscoveryDone: {},
allDone: {},
enterprise: {},
fileHandler: {},
postProcessByDom: {},
postProcessByHtml: postProcessByHtml,
render: postProcessByHtml,
routeDiscoveryDone: {},
routeProcess: {},
router: {},
scullySystem: {},
};

export const pluginTypes = [
'router',
'render',
'rendererDom',
'routeProcess',
'fileHandler',
'allDone',
'routeDiscoveryDone',
'enterprise',
'fileHandler',
'postProcessByDom',
'postProcessByHtml',
'render',
'routeDiscoveryDone',
'routeProcess',
'router',
'scullySystem',
] as const;

Expand All @@ -58,12 +59,12 @@ export const registerPlugin = <T extends keyof PluginFuncs>(
plugin[routeProcessPriority] = typeof pluginOptions === 'number' ? pluginOptions : 100;
break;
case 'render':
logWarn(`Using deprecated plugin type:"${yellow('render')}" use "${yellow('rendererHtml')}" instead`);
logWarn(`Using deprecated plugin type:"${yellow('render')}" use "${yellow('postProcessByHtml')}" instead`);
break;
case 'allDone':
case 'enterprise':
case 'rendererHtml':
case 'rendererDom':
case 'postProcessByHtml':
case 'postProcessByDom':
case 'routeDiscoveryDone':
case 'scullySystem':
break;
Expand All @@ -88,7 +89,7 @@ function assertNeverForPluginType(type: never | string, name: string): never {
----------------------------------------------------------------------------------------------
Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}".
The first parameter of registerPlugin needs to be one of:
'fileHandler', 'router', 'render', 'rendererDom', 'routeProcess', 'allDone', 'enterprise', or 'routeDiscoveryDone'
'fileHandler', 'router', 'render', 'postProcessByDom', 'routeProcess', 'allDone', 'enterprise', or 'routeDiscoveryDone'
----------------------------------------------------------------------------------------------
`);
}
4 changes: 2 additions & 2 deletions libs/scully/src/lib/pluginManagement/pluginWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export async function wrap(type: string, name: string | symbol, plugin: (...args
id += args[0];
currentRoute = args[0];
case 'render':
case 'rendererHtml':
case 'rendererDom':
case 'postProcessByHtml':
case 'postProcessByDom':
id += args[1].route;
currentRoute = args[1].route;
case 'fileHandler':
Expand Down
2 changes: 1 addition & 1 deletion libs/scully/src/lib/renderPlugins/contentRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logWarn, yellow } from '../utils/log';
import { convertAndInjectContent } from './content-render-utils/convertAndInjectContent';
import { readFileAndCheckPrePublishSlug } from './content-render-utils/readFileAndCheckPrePublishSlug';

registerPlugin('rendererDom', 'contentFolder', contentRenderPlugin);
registerPlugin('postProcessByDom', 'contentFolder', contentRenderPlugin);

export async function contentRenderPlugin(dom: JSDOM, route: HandledRoute): Promise<JSDOM> {
const file = route.templateFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { registerPlugin } from '../pluginManagement/pluginRepository';
import { ContentTextRoute } from '../routerPlugins/handledRoute.interface';
import { logError, yellow } from '../utils/log';
import { convertAndInjectContent } from './content-render-utils/convertAndInjectContent';
registerPlugin('rendererDom', 'contentText', contentTextRenderPlugin);
registerPlugin('postProcessByDom', 'contentText', contentTextRenderPlugin);

export async function contentTextRenderPlugin(dom: JSDOM, route: ContentTextRoute): Promise<JSDOM> {
const contentType = route.contentType || route.config.contentType;
Expand Down
Loading

0 comments on commit c3e4baa

Please sign in to comment.