mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
feat: Redirect old documentation links.
This commit is contained in:
@@ -116,5 +116,8 @@
|
||||
"Multi-line code blocks",
|
||||
"HTML Tags"
|
||||
],
|
||||
"ignorePaths": ["packages/mermaid/src/docs/CHANGELOG.md"]
|
||||
"ignorePaths": [
|
||||
"packages/mermaid/src/docs/CHANGELOG.md",
|
||||
"packages/mermaid/src/docs/.vitepress/redirect.ts"
|
||||
]
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ function nav() {
|
||||
{ text: 'Intro', link: '/intro/', activeMatch: '/intro/' },
|
||||
{
|
||||
text: 'Configuration',
|
||||
link: '/config/Tutorials',
|
||||
link: '/config/configuration',
|
||||
activeMatch: '/config/',
|
||||
},
|
||||
{ text: 'Syntax', link: '/syntax/classDiagram', activeMatch: '/syntax/' },
|
||||
@@ -118,6 +118,7 @@ function sidebarConfig() {
|
||||
text: '⚙️ Deployment and Configuration',
|
||||
collapsible: true,
|
||||
items: [
|
||||
{ text: 'Configuration', link: '/config/configuration' },
|
||||
{ text: 'Tutorials', link: '/config/Tutorials' },
|
||||
{ text: 'API-Usage', link: '/config/usage' },
|
||||
{ text: 'Mermaid API Configuration', link: '/config/setup/README' },
|
||||
@@ -126,7 +127,6 @@ function sidebarConfig() {
|
||||
{ text: 'Accessibility', link: '/config/accessibility' },
|
||||
{ text: 'Mermaid CLI', link: '/config/mermaidCLI' },
|
||||
{ text: 'Advanced usage', link: '/config/n00b-advanced' },
|
||||
{ text: 'Configuration', link: '/config/configuration' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
27
packages/mermaid/src/docs/.vitepress/redirect.spec.ts
Normal file
27
packages/mermaid/src/docs/.vitepress/redirect.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { getBaseFile } from './redirect';
|
||||
|
||||
test.each([
|
||||
['http://localhost:1234/mermaid/#/flowchart.md', 'flowchart'],
|
||||
['http://localhost/mermaid/#/flowchart.md', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/flowchart.md', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/./flowchart', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/flowchart', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#flowchart', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/flowchart', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/flowchart.md?id=no-id', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/./flowchart.md?id=no-id', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/flowchart?id=no-id', 'flowchart'],
|
||||
['https://mermaid-js.github.io/mermaid/#/language-highlight', 'language-highlight'],
|
||||
['https://mermaid-js.github.io/mermaid/#/language-highlight.md', 'language-highlight'],
|
||||
])('should process url %s to %s', (link, expected) => {
|
||||
expect(getBaseFile(link)).toBe(expected);
|
||||
});
|
||||
|
||||
test('should throw for invalid URL', () => {
|
||||
// Not mermaid domain
|
||||
expect(() => getBaseFile('https://www.google.com')).toThrowError();
|
||||
|
||||
// Not `/mermaid/` path
|
||||
expect(() => getBaseFile('http://localhost/#/flowchart.md')).toThrowError();
|
||||
});
|
65
packages/mermaid/src/docs/.vitepress/redirect.ts
Normal file
65
packages/mermaid/src/docs/.vitepress/redirect.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
export const getBaseFile = (link: string): string => {
|
||||
const url = new URL(link);
|
||||
if (
|
||||
(url.hostname !== 'mermaid-js.github.io' && url.hostname !== 'localhost') ||
|
||||
url.pathname !== '/mermaid/'
|
||||
) {
|
||||
throw new Error('Not mermaidjs url');
|
||||
}
|
||||
const hash = url.hash
|
||||
.toLowerCase()
|
||||
.replace('.md', '')
|
||||
.replace(/^#\/?/g, '')
|
||||
.replace(/^\.\//g, '')
|
||||
.split('?')[0];
|
||||
return hash;
|
||||
};
|
||||
|
||||
const redirectMap: Record<string, string> = {
|
||||
'8.6.0_docs': '',
|
||||
accessibility: 'config/theming',
|
||||
breakingchanges: '',
|
||||
c4c: 'syntax/c4c',
|
||||
classdiagram: 'syntax/classDiagram',
|
||||
configuration: 'config/configuration',
|
||||
demos: 'misc/integrations',
|
||||
development: 'community/development',
|
||||
directives: 'config/directives',
|
||||
entityrelationshipdiagram: 'syntax/entityRelationshipDiagram',
|
||||
examples: 'syntax/examples',
|
||||
faq: 'misc/faq',
|
||||
flowchart: 'syntax/flowchart',
|
||||
gantt: 'syntax/gantt',
|
||||
gitgraph: 'syntax/gitgraph',
|
||||
integrations: 'misc/integrations',
|
||||
'language-highlight': '',
|
||||
markdown: '',
|
||||
mermaidapi: 'config/usage',
|
||||
mermaidcli: 'config/mermaidCLI',
|
||||
mindmap: 'syntax/mindmap',
|
||||
'more-pages': '',
|
||||
'n00b-advanced': 'config/n00b-advanced',
|
||||
'n00b-gettingstarted': 'intro/n00b-gettingStarted',
|
||||
'n00b-overview': 'community/n00b-overview',
|
||||
'n00b-syntaxreference': '',
|
||||
newdiagram: 'community/newDiagram',
|
||||
pie: 'syntax/pie',
|
||||
plugins: '',
|
||||
quickstart: 'intro/n00b-gettingStarted',
|
||||
requirementdiagram: 'syntax/requirementDiagram',
|
||||
security: 'community/security',
|
||||
sequencediagram: 'syntax/sequenceDiagram',
|
||||
setup: '',
|
||||
statediagram: 'syntax/stateDiagram',
|
||||
themes: 'config/theming',
|
||||
theming: 'config/theming',
|
||||
tutorials: 'config/Tutorials',
|
||||
upgrading: '',
|
||||
usage: 'config/usage',
|
||||
'user-journey': 'syntax/userJourney',
|
||||
};
|
||||
|
||||
export const getRedirect = (link: string): string | undefined => {
|
||||
const base = getBaseFile(link);
|
||||
return redirectMap[base];
|
||||
};
|
@@ -32,6 +32,17 @@ features:
|
||||
|
||||
<script setup>
|
||||
import { VPTeamMembers } from 'vitepress/theme'
|
||||
import { getRedirect } from './.vitepress/redirect';
|
||||
|
||||
try{
|
||||
const newPath = getRedirect(window.location);
|
||||
if(newPath) {
|
||||
console.log(`Redirecting to ${newPath} from ${window.location}`);
|
||||
window.location.replace(`/mermaid/${getRedirect(window.location)}.html`);
|
||||
}
|
||||
}catch(e){
|
||||
}
|
||||
|
||||
const websiteSVG = {
|
||||
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-globe"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"></line><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"></path></svg>'
|
||||
}
|
||||
|
Reference in New Issue
Block a user