How do I add categories or tags to a Svelte/Sapper markdown site?

隐身守侯 提交于 2020-01-16 09:47:03

问题


Forking this question off from Sapper/Svelte: How do I add markdown files? to help future searchers:

I see that all the posts will have a link right after the Top-Level Domain Ex www.example.com/post1, www.example.com/post2. But what if someone using the template wants to categorize the posts. Ex www.example.com/svelte-posts/post1, www.example.com/vuejs-posts/post1


回答1:


If you want traditional WordPress-style categories I would add that to the markdown front matter of the posts (Jekyll docs) and then create a category page template using dynamic parameters, with links to any categories in your individual post template as well.

However, if there are a limited number of categories you know ahead of time, and you want the category in the URL before the post name, it might be simpler, though limiting over time, to have separate blogs/folders of posts and use those the way the Svelte site uses the blog folder. This would not work well if you wanted a traditional chronological index of all of the posts from any category though, so if you did want that use the front matter approach above and don't worry about the URL for individual posts.

Also in my experience, tags are almost always better than categories, because you can add as many as you like. What if you wrote a post comparing Svelte and Vue? Why not have it appear in both? Then you want tags not categories. WordPress has a long, confusing history with this where I think they finally made categories behave like tags because they got sick of dealing with people using categories when they wanted tags and complaining.



来源:https://stackoverflow.com/questions/58674044/how-do-i-add-categories-or-tags-to-a-svelte-sapper-markdown-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!