Skip to content
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

Parse permalinks placeholders from markdown files name #31

Closed
chawyehsu opened this issue Mar 24, 2019 · 5 comments · Fixed by #32
Closed

Parse permalinks placeholders from markdown files name #31

chawyehsu opened this issue Mar 24, 2019 · 5 comments · Fixed by #32

Comments

@chawyehsu
Copy link
Contributor

Just like what Hexo does.

saber-config.yml

permalinks:
  post: /posts/:year/:month/:day/:slug.html

./pages/_posts/2019-03-24-hello-saber.md

---
layout: post
date: 2019-03-24
---

Expect:

./pages/_posts/2019-03-24-hello-saber.md becomes /posts/2019/03/24/hello-saber.html

Actual:

./pages/_posts/2019-03-24-hello-saber.md becomes /posts/2019/03/24/2019-03-24-hello-saber.html

@egoist
Copy link
Collaborator

egoist commented Mar 24, 2019

Nice we just need to extract the date from filename and use it as the default value of page.attributes.createdAt 👌

@chawyehsu
Copy link
Contributor Author

chawyehsu commented Mar 24, 2019

Proposal:

A new saber config property: postName with the default value: :title.md. The :slug of a post is :title by default.

When users define postName to :year-:month-:day-:title.md, extract date :year-:month-:day as attributes.createdAt, and :title as:slug.

Similar to Hexo: https://github.com/hexojs/hexo/blob/087b3fa456aa97279df61a7f05e59c932051ee2b/lib/plugins/processor/post.js#L49-L54

@chawyehsu
Copy link
Contributor Author

Another way is making a common page filename format with a built-in regex, inspired by zola.

Another exception to that rule is that a filename starting with a datetime (YYYY-mm-dd or a RFC3339 datetime) followed by an underscore (_) or a dash (-) will use that date as the page date, unless already set in the front-matter. The page name will be anything after _/- so a filename like 2018-10-10-hello-world.md will be available at [base_url]/hello-world. Note that the full RFC3339 datetime contains colons, which is not a valid character in a filename on Windows. —— zola doc

In this way, no extra postName config property needed, page filename format becomes strict but still behaves the same way as Hexo.

@egoist
Copy link
Collaborator

egoist commented Mar 26, 2019

we have the permalinks option https://saberjs.org/docs/permalinks.html#placeholders

@chawyehsu
Copy link
Contributor Author

Yeah, I know that option. What I want to say is that we need a way to detech whether the filename contains datetime or not, thus I provide two methods to do so. One is customizable and the other is strict. I prefer the latter, and will try to implement it.

egoist pushed a commit that referenced this issue Mar 26, 2019
closes #31 

* feat: support extracting datetime from post filename

* parse fileName once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants