vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Use the hash of the article title to provide the article url

Open bd-dxg opened this issue 1 year ago • 16 comments

Is your feature request related to a problem? Please describe.

In the process of daily use, non-native English speakers will use their native language to write article titles when writing articles.

However, the url obtained by such an article after publication will be encoded, resulting in the blog's post address becoming very long

Describe the solution you'd like

Here's an example.

image

After copying the url, the URL becomes like this:

https://blog.jimmyxuexue.top/front-end/%E6%8A%98%E8%85%BE/%E5%AE%9E%E7%8E%B0%E9%82%AE%E7%AE%B1%E8%BE%85%E5%8A%A9%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD.html

This is very inelegant in the process of sharing articles, the address is too messy, and some editing boxes will limit the number of characters.

Describe alternatives you've considered

I hope vitepress can provide a configuration item that automatically turns the article address into a hash value of the article title (preferably to control the length, such as 6 bits, 10 bits, etc.)

So even if I change the content of the article, the title of the article will not change, and the address of the article will not change

Additional context

Original url:

https://blog.jimmyxuexue.top/front-end/%E6%8A%98%E8%85%BE/%E5%AE%9E%E7%8E%B0%E9%82%AE%E7%AE%B1%E8%BE%85%E5%8A%A9%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD.html

Changed url:

https://blog.jimmyxuexue.top/front-end/jl34n23rnl.html

Change only the article title, keep the folder path

Validations

bd-dxg avatar Dec 13 '23 06:12 bd-dxg

我也有这个问题,不过简单地使用内存Map实现了一个静态短链接服务如,justin3go.com/s?u=590f2bc50aa

也许还可以尝试一下市面上的一些短链接服务

Justin3go avatar Dec 25 '23 03:12 Justin3go

我也有这个问题,不过简单地使用内存Map实现了一个静态短链接服务如,justin3go.com/s?u=590f2bc50aa

也许还可以尝试一下市面上的一些短链接服务

并不方便,而且那些公用短链服务可能被腾讯标红或者拦截 Not convenient, and those public short URL services may be red or blocked by Tencent

bd-dxg avatar Dec 25 '23 03:12 bd-dxg

Ah, so it can't be an actual hash (since you want it to remain constant across edits), it should be a random string which is stored in some file(s) (tracked by your vcs) so that it doesn't change across builds.

The most feasible way I see is to just store this in frontmatter of each post:

---
slug: V1StGXR8
---

And in config.ts generate rewrites using fast-glob + gray-matter

brc-dd avatar Dec 31 '23 11:12 brc-dd

Ah, so it can't be an actual hash (since you want it to remain constant across edits), it should be a random string which is stored in some file(s) (tracked by your vcs) so that it doesn't change across builds.啊,所以它不能是一个实际的散列(因为你希望它在编辑过程中保持不变),它应该是一个随机字符串,存储在某些文件中(由你的 vcs 跟踪),这样它就不会跨构建的变化。

The most feasible way I see is to just store this in frontmatter of each post:我认为最可行的方法是将其存储在每个帖子的 frontmatter 中:

---
slug: V1StGXR8
---

And in config.ts generate rewrites using fast-glob + gray-matter并在 config.ts 中使用 fast-glob + grey-matter 生成重写

You may not understand what I mean, I mean hashing the title of the article, if I have an article that has been published, I find something wrong with the content and modify it, but I will not change the title of the article (rarely will I change the title),

To clarify again, I just said to hash the title of the article, not the entire content of the article. My expression has gone through the translator, and I don't know if my description is accurate.

bd-dxg avatar Jan 01 '24 04:01 bd-dxg

Ah, okay. Now I get it. Earlier I thought you wanted hash of whole document.

brc-dd avatar Jan 01 '24 05:01 brc-dd

我想用frontmatter中的属性来生成路由,能实现吗?

wstee avatar Jan 19 '24 03:01 wstee

Ah, okay. Now I get it. Earlier I thought you wanted hash of whole document.

hi, I want to ask, is there any progress on this issue now? I try to provide my blog address to others, but obviously the url address is very long, which is too ugly

https://github.com/vuejs/vitepress/discussions/1646#discussioncomment-9841679

bd-dxg avatar Jun 21 '24 16:06 bd-dxg

I have one question, even if we do rewrites on pages, how would the links to headings look? They will also get url encoded 👀

brc-dd avatar Jun 22 '24 08:06 brc-dd

I have one question, even if we do rewrites on pages, how would the links to headings look? They will also get url encoded 👀

Indeed, this is a topic worth discussing, because in addition to the article title, the URL may also include Chinese-named categories, as shown in the figure:

2024-06-23_14-24-23

Not only that, but also consider : The Anchor element: 2024-06-23_14-39-30

This may increase the difficulty and require enough patience to solve the problem

bd-dxg avatar Jun 23 '24 06:06 bd-dxg

I suddenly had a fantastic idea, maybe we don't have to think about how to shorten the url, we just need to add a button or a element to the article page, display the copy article address, and write the url with Chinese to the user's clipboard.

https://bddxg.top/article/note/工程化/脚手架/Vite笔记.html

@brc-dd

bd-dxg avatar Jun 23 '24 06:06 bd-dxg

Any good UI idea? 👀 I think below outline might be a good place to keep it, but not sure how it would look on smaller viewports. Also, it won't look nice if outline is long. Some other place maybe.

brc-dd avatar Jun 23 '24 07:06 brc-dd

Any good UI idea? 👀 I think below outline might be a good place to keep it, but not sure how it would look on smaller viewports. Also, it won't look nice if outline is long. Some other place maybe.

Unfortunately, I don't have much experience with UI. Perhaps a codepen search would be a good idea, for example:

https://codepen.io/search/pens?q=share+button

If it's a button layout, I thought it would be a good place to be on the right side of the title (probably dealing with super long title wrapping issues)

2024-06-23_16-18-17

bd-dxg avatar Jun 23 '24 08:06 bd-dxg