-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: add en anchors #2049
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
feat: add en anchors #2049
Conversation
✅ Deploy Preview for vuejs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Looks like that |
Seems to be a duplicate title for composition api / option api.. |
I'm wondering whether we need to include the script in the PR? The script is useful for the initial bulk adding of headings, but do we really need to use it beyond that? Perhaps we could just manually correct the handful of duplicate headers rather than trying to get the script to do it automatically? |
It could be put into a gist instead of directly in the source of docs yes! |
Sounds a good idea. |
# Conflicts: # src/guide/essentials/reactivity-fundamentals.md
I just removed the script related things from my branch. And fixed the duplicated anchor as @Jinjiang suggested. the script posted here, and you may use it at will. /**
* slugify function taken from vitepress
*/
// string.js slugify drops non ascii chars so we have to
// use a custom implementation here
const { remove: removeDiacritics } = require('diacritics')
// eslint-disable-next-line no-control-regex
const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
const slugify = (str) => {
return (
removeDiacritics(str)
// Remove control characters
.replace(rControl, '')
// Replace special characters
.replace(rSpecial, '-')
// Remove continuous separators
.replace(/\-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^\-+|\-+$/g, '')
// ensure it doesn't start with a number (#121)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
)
}
let glob = require('glob');
let path = require('path');
let fs = require('fs');
glob('../../src/**/*.md', { cwd: __dirname }, function (err, files) {
for (let f of files) {
let filePath = path.join(__dirname, f);
let content = fs.readFileSync(filePath, { encoding: 'utf-8' });
let headings = content.match(/^#+ .+$/gm);
for (let h of headings ?? []) {
let _h = h.replace(/{#.+$/, '').trim();
content = content.replace(h, `${_h} {#${slugify(_h)}}`);
}
fs.writeFileSync(filePath, content, { encoding: 'utf-8' });
}
}); |
Seems like this introduced a regression: Check the smaller headings here: https://vuejs.org/guide/essentials/class-and-style.html |
@hymair thanks for figuring it out. I created a PR to fix this. 🙏 |
Description of Problem
close #1998
added a script to generate anchors. It can also re-run for updates.