Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix @see links #1363

Merged
merged 2 commits into from Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/.vitepress/components/api-docs/method.vue
@@ -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
@@ -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
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