Skip to content
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
41 changes: 0 additions & 41 deletions demos/plugins/docs-link-update.js

This file was deleted.

1 change: 1 addition & 0 deletions libs/plugins/docs-link-update/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "../../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] }
5 changes: 5 additions & 0 deletions libs/plugins/docs-link-update/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# scully-plugin-docs-link-update

This is a helper plugin for people using the scully-content plugin with links to other markdown files
If looks for the `[href]` attribute. If the link in there starts with `#` it will put the full route in front of it, so that links _inside_ the page starts working when it's hosted.
It also looks for relative links that end with `.md` and do not start with `http`. For those links it updates the url so it will contain an url relative to the page the link is on.
9 changes: 9 additions & 0 deletions libs/plugins/docs-link-update/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
name: 'plugins-docs-link-update',
preset: '../../../jest.config.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../../coverage/libs/plugins/docs-link-update',
};
10 changes: 10 additions & 0 deletions libs/plugins/docs-link-update/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@scullyio/scully-plugin-docs-link-update",
"version": "0.0.1",
"peerDependencies": {
"@scullyio/scully": "*"
},
"dependencies": {
"jsdom": "^16.2.2"
}
}
1 change: 1 addition & 0 deletions libs/plugins/docs-link-update/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/plugins-docs-link-update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { pluginsDocsLinkUpdate } from './plugins-docs-link-update';

describe('pluginsDocsLinkUpdate', () => {
it('should work', () => {
expect(pluginsDocsLinkUpdate()).toEqual('plugins-docs-link-update');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { HandledRoute, logWarn, registerPlugin, yellow } from '@scullyio/scully';
import { JSDOM } from 'jsdom';

export const docLink = 'docsLink';

const docsLinkPlugin = async (html: string, options: HandledRoute): Promise<string> => {
try {
const dom = new JSDOM(html);
const { window } = dom;
const anchors = Array.from(window.document.querySelectorAll('[href]'));
anchors.forEach((a) => {
const href = a.getAttribute('href');
if (href && href.toLowerCase().endsWith('.md') && !href.toLowerCase().startsWith('http')) {
const myBase = options.route.substring(0, options.route.lastIndexOf('/'));
const newRef = `${myBase}/${href.slice(0, -3)}`;
a.setAttribute('href', newRef);
}
if (href && href.startsWith('#')) {
const newRef = `${options.route}${href}`;
a.setAttribute('href', newRef);
}
});
return dom.serialize();
} catch (e) {
logWarn(`error in docsLink, didn't parse for route "${yellow(options.route)}"`);
}
// in case of failure return unchanged HTML to keep flow going
return html;
};

const validator = async (config) => [];
registerPlugin('render', docLink, docsLinkPlugin, validator);
7 changes: 7 additions & 0 deletions libs/plugins/docs-link-update/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": ["**/*.ts"]
}
12 changes: 12 additions & 0 deletions libs/plugins/docs-link-update/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"rootDir": "./src",
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}
9 changes: 9 additions & 0 deletions libs/plugins/docs-link-update/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js", "**/*.spec.jsx", "**/*.d.ts"]
}
4 changes: 2 additions & 2 deletions libs/scully/src/lib/renderPlugins/executePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const executePluginsForRoute = async (route: HandledRoute) => {
try {
const prResult = await preRender(route);
if (prResult === false) {
logError(`prerender stopped rendering for "${yellow(route.route)}". This route is skipped.`);
logError(`The prerender function stopped rendering for "${yellow(route.route)}". This route is skipped.`);
return '';
}
} catch (e) {
logError(`prerender trowed during rendering for "${yellow(route.route)}". This route is skipped.`);
logError(`The prerender function errorred out during rendering for "${yellow(route.route)}". This route is skipped.`);
/** abort when prerender throws */
return '';
}
Expand Down
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
},
"plugins-google-analytics": {
"tags": []
},
"plugins-docs-link-update": {
"tags": []
}
}
}
4 changes: 2 additions & 2 deletions scully.scully-docs.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ScullyConfig, setPluginConfig, prod } from '@scullyio/scully';
import { DisableAngular } from 'scully-plugin-disable-angular';
import './demos/plugins/docs-link-update';
import { LogRocket } from '@scullyio/plugins/logrocket';
import { GoogleAnalytics } from '@scullyio/plugins/google-analytics';
import { docLink } from '@scullyio/scully-plugin-docs-link-update';

setPluginConfig('md', { enableSyntaxHighlighting: true });

Expand Down Expand Up @@ -37,7 +37,7 @@ export const config: ScullyConfig = {
routes: {
'/docs/:slug': {
type: 'contentFolder',
postRenderers: ['docsLink', ...defaultPostRenderers],
postRenderers: [docLink, ...defaultPostRenderers],
slug: {
folder: './docs',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ exports[`docsSite should have content for all markdown files check html for mark
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css"
>
<link rel="stylesheet"
href="styles.b5d9035702162cff4ba2.css"
href="styles.fb8c2cdba07bb9c610bd.css"
>
<style>
[]{display:grid;height:100vh;grid-template-rows:60px 1fr 60px}[] > header[]{display:grid;margin:0;padding:0 20px;grid-template-columns:120px 1fr;place-items:center right;overflow:none}footer[] h3[], header[] h1[]{margin:0}main[]{padding:10px;background-image:url(scully-bg-s.b01bbd69c8fe3262435d.svg);background-size:cover}.github[]{float:right;margin-top:10px;margin-left:20px}footer[]{padding-top:48px;min-height:250px;display:grid;grid-template-columns:25% 15% 15% 15% 25%;background:var(--scully-green-wash)}.footer-1[]{grid-column-start:2;grid-column-end:2;text-align:center}.footer-2[]{grid-column-start:3;grid-column-end:3;text-align:center}.footer-3[]{grid-column-start:4;grid-column-end:4;text-align:center}a[]{text-decoration:none;color:var(--scully-darkgray);cursor:pointer}.footer-1[] > h3[], .footer-2[] > h3[], .footer-3[] > h3[]{color:var(--scully-green);margin-bottom:10px}@media (max-width:1024px){footer[]{grid-template-columns:16px 1fr 1fr 1fr 16px}nav[]{transform:scale(.9)}}header[]{background:#000;color:#fff;min-height:90px}
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"@scullyio/plugins/demo-lib": ["libs/plugins/demo-lib/src/index.ts"],
"@scul lyio/plugins/scully-plugin-flash-prevention": ["dist/libs/plugins/scully-plugin-flash-prevention"],
"@scullyio/plugins/logrocket": ["libs/plugins/logrocket/src/index.ts"],
"@scullyio/plugins/google-analytics": ["libs/plugins/google-analytics/src/index.ts"]
"@scullyio/plugins/google-analytics": ["libs/plugins/google-analytics/src/index.ts"],
"@scullyio/plugins/docs-link-update": ["libs/plugins/docs-link-update/src/index.ts"]
}
},
"angularCompilerOptions": {
"disableTypeScriptVersionCheck": true
},
"exclude": ["node_modules", "tmp", "dist"]
"exclude": ["node_modules", "tmp", "dist", "tests"]
}
Loading