Skip to content

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

Merged
merged 7 commits into from
Nov 6, 2022
Merged

feat: add en anchors #2049

merged 7 commits into from
Nov 6, 2022

Conversation

wxsms
Copy link
Member

@wxsms wxsms commented Oct 26, 2022

Description of Problem

close #1998

added a script to generate anchors. It can also re-run for updates.

@netlify
Copy link

netlify bot commented Oct 26, 2022

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit e22cc42
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/6365bbff6d7ced00074a77c9
😎 Deploy Preview https://deploy-preview-2049--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@wxsms
Copy link
Member Author

wxsms commented Oct 26, 2022

Looks like that reactivity-fundamentals.md has 2 headings with same name, which will generate same slug id and cause vitepress complain. Any idea?

@edimitchel
Copy link
Contributor

Looks like that reactivity-fundamentals.md has 2 headings with same name, which will generate same slug id and cause vitepress complain. Any idea?

Seems to be a duplicate title for composition api / option api..

@Jinjiang
Copy link
Member

Jinjiang commented Nov 3, 2022

I suggest we just follow the current rule to add an incremental number after the duplicated ids. That's also what you can get on the current doc site.

image

For example, the second #reactive-proxy-vs-original should become #reactive-proxy-vs-original-1 automatically.

Thanks.

@skirtles-code
Copy link
Contributor

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?

@edimitchel
Copy link
Contributor

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!

@Jinjiang
Copy link
Member

Jinjiang commented Nov 3, 2022

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.

wxsms added 2 commits November 4, 2022 09:32
# Conflicts:
#	src/guide/essentials/reactivity-fundamentals.md
@wxsms
Copy link
Member Author

wxsms commented Nov 4, 2022

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' });
  }
});

@wxsms wxsms changed the title feat: add en anchor & script (close #1998) feat: add en anchors (close #1998) Nov 4, 2022
@wxsms wxsms changed the title feat: add en anchors (close #1998) feat: add en anchors Nov 4, 2022
@yyx990803 yyx990803 merged commit ee4f310 into vuejs:main Nov 6, 2022
@hymair
Copy link

hymair commented Nov 6, 2022

Seems like this introduced a regression:

image

Check the smaller headings here: https://vuejs.org/guide/essentials/class-and-style.html

cc @wxsms @Jinjiang @skirtles-code @edimitchel

@Jinjiang
Copy link
Member

Jinjiang commented Nov 6, 2022

@hymair thanks for figuring it out. I created a PR to fix this. 🙏

d-darwin pushed a commit to d-darwin/docs-ru that referenced this pull request Nov 13, 2022
@wxsms wxsms deleted the feat/en-anchor branch November 17, 2022 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add english anchors
6 participants