Showcase section to the docs - keepings docs up to date (#4055)

* Add a Showcase section to the docs with Swimm

* Build docs

* Move FAQ to Config

* Create showcases page

* Build docs

* Prettier

* feat: Redirect old docs URLs

---------

Co-authored-by: Sidharth Vinod <sidharthv96@gmail.com>
This commit is contained in:
Omer Rosenbaum
2023-02-07 19:45:48 +02:00
committed by GitHub
parent 923ddc8309
commit 73ee9e9a92
10 changed files with 57 additions and 42 deletions

View File

@@ -2,7 +2,7 @@
> >
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
> >
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/misc/faq.md](../../packages/mermaid/src/docs/misc/faq.md). > ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/faq.md](../../packages/mermaid/src/docs/config/faq.md).
# Frequently Asked Questions # Frequently Asked Questions

View File

@@ -2,7 +2,7 @@
> >
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
> >
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/misc/integrations.md](../../packages/mermaid/src/docs/misc/integrations.md). > ## Please edit the corresponding file in [/packages/mermaid/src/docs/ecosystem/integrations.md](../../packages/mermaid/src/docs/ecosystem/integrations.md).
# Integrations # Integrations

View File

@@ -0,0 +1,9 @@
> **Warning**
>
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
>
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/ecosystem/showcases.md](../../packages/mermaid/src/docs/ecosystem/showcases.md).
# Showcases
- [Swimm - Up-to-date diagrams with Swimm, the knowledge management tool for code](https://docs.swimm.io/Features/diagrams-and-charts).

View File

@@ -77,8 +77,8 @@ function sidebarAll() {
], ],
}, },
...sidebarSyntax(), ...sidebarSyntax(),
...sidebarEcosystem(),
...sidebarConfig(), ...sidebarConfig(),
...sidebarMisc(),
...sidebarCommunity(), ...sidebarCommunity(),
]; ];
} }
@@ -125,19 +125,20 @@ function sidebarConfig() {
{ text: 'Accessibility', link: '/config/accessibility' }, { text: 'Accessibility', link: '/config/accessibility' },
{ text: 'Mermaid CLI', link: '/config/mermaidCLI' }, { text: 'Mermaid CLI', link: '/config/mermaidCLI' },
{ text: 'Advanced usage', link: '/config/n00b-advanced' }, { text: 'Advanced usage', link: '/config/n00b-advanced' },
{ text: 'FAQ', link: '/config/faq' },
], ],
}, },
]; ];
} }
function sidebarMisc() { function sidebarEcosystem() {
return [ return [
{ {
text: '📚 Misc', text: '📚 Ecosystem',
collapsible: true, collapsible: true,
items: [ items: [
{ text: 'Use-Cases and Integrations', link: '/misc/integrations' }, { text: 'Showcases', link: '/ecosystem/showcases' },
{ text: 'FAQ', link: '/misc/faq' }, { text: 'Use-Cases and Integrations', link: '/ecosystem/integrations' },
], ],
}, },
]; ];

View File

@@ -10,9 +10,6 @@ export default {
// register global components // register global components
app.component('Mermaid', Mermaid); app.component('Mermaid', Mermaid);
router.onBeforeRouteChange = (to) => { router.onBeforeRouteChange = (to) => {
if (router.route.path !== '/') {
return;
}
try { try {
const newPath = getRedirect(to); const newPath = getRedirect(to);
if (newPath) { if (newPath) {

View File

@@ -5,31 +5,34 @@ import { expect, test } from 'vitest';
import { getRedirect } from './redirect'; import { getRedirect } from './redirect';
test.each([ test.each([
// Old docs, localhost
['http://localhost:1234/mermaid/#/flowchart.md', 'syntax/flowchart.html'], ['http://localhost:1234/mermaid/#/flowchart.md', 'syntax/flowchart.html'],
['http://localhost/mermaid/#/flowchart.md', 'syntax/flowchart.html'], ['http://localhost/mermaid/#/flowchart.md', 'syntax/flowchart.html'],
['https://mermaid-js.github.io/mermaid/#/flowchart.md', 'syntax/flowchart.html'], // Old docs, github pages
['https://mermaid.js.org/#/flowchart.md', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/flowchart.md', 'syntax/flowchart.html'], // without dot
['https://mermaid-js.github.io/mermaid/#/./flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/./flowchart', 'syntax/flowchart.html'], // with dot
['https://mermaid-js.github.io/mermaid/#/flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#flowchart', 'syntax/flowchart.html'], // without slash
['https://mermaid-js.github.io/mermaid/#flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/flowchart', 'syntax/flowchart.html'], // with slash
['https://mermaid-js.github.io/mermaid/#/flowchart', 'syntax/flowchart.html'], ['https://mermaid-js.github.io/mermaid/#/flowchart.md?id=my-id', 'syntax/flowchart.html#my-id'], // with id
['https://mermaid-js.github.io/mermaid/#/flowchart.md?id=my-id', 'syntax/flowchart.html#my-id'], ['https://mermaid-js.github.io/mermaid/#/./flowchart.md?id=my-id', 'syntax/flowchart.html#my-id'], // with id and dot
['https://mermaid-js.github.io/mermaid/#/./flowchart.md?id=my-id', 'syntax/flowchart.html#my-id'],
[ [
'https://mermaid-js.github.io/mermaid/#/flowchart?another=test&id=my-id&one=more', 'https://mermaid-js.github.io/mermaid/#/flowchart?another=test&id=my-id&one=more', // with multiple params
'syntax/flowchart.html#my-id', 'syntax/flowchart.html#my-id',
], ],
['https://mermaid-js.github.io/mermaid/#/n00b-advanced', 'config/n00b-advanced.html'], ['https://mermaid-js.github.io/mermaid/#/n00b-advanced', 'config/n00b-advanced.html'], // without .md
['https://mermaid-js.github.io/mermaid/#/n00b-advanced.md', 'config/n00b-advanced.html'], ['https://mermaid-js.github.io/mermaid/#/n00b-advanced.md', 'config/n00b-advanced.html'], // with .md
[ [
'https://mermaid-js.github.io/mermaid/#/flowchart?id=a-node-in-the-form-of-a-circle', 'https://mermaid-js.github.io/mermaid/#/flowchart?id=a-node-in-the-form-of-a-circle', // with id, without .md
'syntax/flowchart.html#a-node-in-the-form-of-a-circle', 'syntax/flowchart.html#a-node-in-the-form-of-a-circle',
], ],
// Old docs, without base path, new domain
['https://mermaid.js.org/#/flowchart.md', 'syntax/flowchart.html'],
// New docs, without base path, new domain
['https://mermaid.js.org/misc/faq.html', 'configure/faq.html'],
[
'https://mermaid.js.org/misc/faq.html#frequently-asked-questions',
'configure/faq.html#frequently-asked-questions',
], // with hash
])('should process url %s to %s', (link: string, path: string) => { ])('should process url %s to %s', (link: string, path: string) => {
expect(getRedirect(link)).toBe(path); expect(getRedirect(link)).toBe(path);
}); });
test('should throw for invalid URL', () => {
// Not mermaid domain
expect(() => getRedirect('https://www.google.com')).toThrowError();
});

View File

@@ -1,4 +1,4 @@
export interface Redirect { interface Redirect {
path: string; path: string;
id?: string; id?: string;
} }
@@ -7,15 +7,7 @@ export interface Redirect {
* Extracts the base slug from the old URL. * Extracts the base slug from the old URL.
* @param link - The old URL. * @param link - The old URL.
*/ */
const getBaseFile = (link: string): Redirect => { const getBaseFile = (url: URL): Redirect => {
const url = new URL(link);
if (
url.hostname !== 'mermaid-js.github.io' &&
url.hostname !== 'mermaid.js.org' &&
url.hostname !== 'localhost'
) {
throw new Error('Not mermaidjs url');
}
const [path, params, ...rest] = url.hash const [path, params, ...rest] = url.hash
.toLowerCase() .toLowerCase()
.replace('.md', '') .replace('.md', '')
@@ -32,7 +24,7 @@ const getBaseFile = (link: string): Redirect => {
return { path, id }; return { path, id };
}; };
const redirectMap: Record<string, string> = { const idRedirectMap: Record<string, string> = {
'8.6.0_docs': '', '8.6.0_docs': '',
accessibility: 'config/theming', accessibility: 'config/theming',
breakingchanges: '', breakingchanges: '',
@@ -76,15 +68,25 @@ const redirectMap: Record<string, string> = {
'user-journey': 'syntax/userJourney', 'user-journey': 'syntax/userJourney',
}; };
const urlRedirectMap: Record<string, string> = {
'/misc/faq.html': 'configure/faq.html',
};
/** /**
* *
* @param link - The old documentation URL. * @param link - The old documentation URL.
* @returns The new documentation path. * @returns The new documentation path.
*/ */
export const getRedirect = (link: string): string | undefined => { export const getRedirect = (link: string): string | undefined => {
const { path, id } = getBaseFile(link); const url = new URL(link);
if (!(path in redirectMap)) { // Redirects for deprecated vitepress URLs
return; if (url.pathname in urlRedirectMap) {
return `${urlRedirectMap[url.pathname]}${url.hash}`;
}
// Redirects for old docs URLs
const { path, id } = getBaseFile(url);
if (path in idRedirectMap) {
return `${idRedirectMap[path]}.html${id ? `#${id}` : ''}`;
} }
return `${redirectMap[path]}.html${id ? `#${id}` : ''}`;
}; };

View File

@@ -0,0 +1,3 @@
# Showcases
- [Swimm - Up-to-date diagrams with Swimm, the knowledge management tool for code](https://docs.swimm.io/Features/diagrams-and-charts).