Skip to content

Commit

Permalink
docs: fix @see links (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Sep 9, 2022
1 parent 0c6e9b1 commit 4efa530
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion docs/.vitepress/components/api-docs/method.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup lang="ts">
import type { Method } from './method';
import MethodParameters from './method-parameters.vue';
import { slugify } from '../../shared/utils/slugify';
const props = defineProps<{ method: Method }>();
function seeAlsoToUrl(see: string): string {
const [, module, method] = see.replace(/\(.*/, '').split('\.');
return module + '.html#' + method;
return module + '.html#' + slugify(method);
}
</script>

Expand Down
16 changes: 16 additions & 0 deletions docs/.vitepress/shared/utils/slugify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function slugify(value: string): string {
// Copied from https://github.com/vuejs/docs/blob/b392b068fb893e3ac6079710fe34decbde7a3be3/src/api/ApiIndex.vue#L50-L65
return (
value
// Replace special characters
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g, '-')
// Remove continuous separators
.replace(/\-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^\-+|\-+$/g, '')
// ensure it doesn't start with a number (like #123)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
);
}
18 changes: 1 addition & 17 deletions docs/api/ApiIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script setup lang="ts">
import { computed, ref } from 'vue';
import { slugify } from '../.vitepress/shared/utils/slugify';
import apiSearchIndex from './api-search-index.json';
import { APIGroup } from './api-types';
Expand Down Expand Up @@ -42,23 +43,6 @@ const filtered = computed(() => {
})
.filter((i) => i) as APIGroup[];
});
// same as vitepress' slugify logic
function slugify(text: string): string {
return (
text
// Replace special characters
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g, '-')
// Remove continuous separators
.replace(/\-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^\-+|\-+$/g, '')
// ensure it doesn't start with a number (like #123)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
);
}
</script>

<template>
Expand Down

0 comments on commit 4efa530

Please sign in to comment.