vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.08k stars 2.11k forks source link

Add permalink feature #285

Open humbinal opened 3 years ago

humbinal commented 3 years ago

Did vitpress support permalink in frontmatter? I try to config but not work.

seangwright commented 3 years ago

The docs show this feature as missing from Vitepress

https://vitepress.vuejs.org/guide/differences-from-vuepress.html#general

lipengzhou commented 1 year ago

+1

kid1412621 commented 1 year ago

It's the only blocker for me to migrate from vuepress.

StefanoCecere commented 1 year ago

sorry i didn't understand if permalinks (a must have for me, too) has a working workaround or not. or if it'll every have

brc-dd commented 1 year ago

Regarding the has-workaround label, you can use rewrites to write some code like this. Feel free to customize it or comment here if you're having any issues. Note that you'll need to restart the server (press r on terminal) each time you create a new file or add date in it's frontmatter to regenerate rewrites.

// .vitepress/config.ts

import { defineConfig } from 'vitepress'
import fg from 'fast-glob'
import matter from 'gray-matter'

const rewrites = {}
const pages = await fg('**/*.md', { ignore: ['node_modules/**'] })

pages.map((page) => {
  const { date } = matter.read(page).data as { date: Date }

  if (date)
    rewrites[page] = `${date.getFullYear()}/${
      date.getMonth() + 1
    }/${date.getDate()}/${page}`
})

export default defineConfig({
  rewrites
})