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

Permalink Generation and customization for content #294

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

manikmagar
Copy link
Member

This pull request implements Permalink/URI Generation and customization in JBake.

It is driven by a property permalink in jbake.properties file. Sample permalink pattern can be permalink=/:blog:/:title which will generate urls as blog\first-post.html.

If permalink is not specified then default pattern is /:filepath.

Every keyword should be separated with '/:'. It allows you to use any keywords from content header. eg. /:slug/:tags/:title.

Few Rules:

Some keywords are reserved for specific format. Below is the list of such keywords -

  1. /:filepath: This keyword will result it addition of relative source file path from content folder. If you want to maintain the content folder structure in output then, permalink=/:filepath will result in generating URI structure same as source files.
  2. /:filename: This keyword will result in addition of source file name (without extension).
  3. /:YEAR, /:MONTH, :DAY: These keywords will add a related date part from content published date to url.
  4. Adding Static words - Static words can be added in url by using ':' as suffix in permalink. For example, permalink=/:blog:/:filename will result in generation of urls like /blog/First-post.html

Using permalink in templates

Generated permalinks can be accessed in templates as content.permalink.

Extension-less permalinks

If ur.noExtension is set to true then all permalinks will be extension-less. For example, permalink=/:blog:/:filename will generate /blog/First-post/.

How to use different permalink patterns for each content type.

It is possible to use different permalink patterns based on content type. For example, post and page content type can use their own permalink patterns. permalink property will always be used as a default pattern for every content. To customize it based on content type, you can add another property permalink.{type} and specify pattern for it.

Sample configuration -
permalink=/:filepath
permalink.post=/:blog:/:filename
permalink.page=/:filename

Above configuration will result in pages with uri as filenames only, while posts will have suffix /blog/ for url. Any other content type will keep using /:filepath pattern.

@coveralls
Copy link

coveralls commented Jun 26, 2016

Coverage Status

Coverage increased (+1.3%) to 66.291% when pulling 84cf4ec on manikmagar:mm-jbake-permalink into 6e4a165 on jbake-org:master.

@coveralls
Copy link

coveralls commented Jun 26, 2016

Coverage Status

Coverage increased (+1.5%) to 66.5% when pulling cee25ca on manikmagar:mm-jbake-permalink into 6e4a165 on jbake-org:master.

@coveralls
Copy link

coveralls commented Jul 8, 2016

Coverage Status

Coverage increased (+3.7%) to 68.699% when pulling cd22f18 on manikmagar:mm-jbake-permalink into 6e4a165 on jbake-org:master.

@jonbullock
Copy link
Member

Interesting idea... I'm interested to understand what drove you to make this change? What is the use case you wanted to achieve that you couldn't without the change? As the output is driven by the source structure.

@jonbullock jonbullock added this to the v2.5.0 milestone Sep 26, 2016
@jonbullock jonbullock self-assigned this Sep 26, 2016
@jonbullock jonbullock modified the milestones: v3.0.0, v2.5.0 Sep 26, 2016
@manikmagar
Copy link
Member Author

@jonbullock , Sorry for the late reply, but I remember I was migrating my wordpress site where all posts got exported to root of the folder but in wordpress they had different url pattern. So instead of putting them into folder structure, I thought there should be a way to define permalink pattern. Hence I added this one :).

@jonbullock
Copy link
Member

Thanks for providing the context behind this @manikmagar it has certainly helped 👍

@manikmagar
Copy link
Member Author

This was implemented a while back (on maven), I think I will rebase to current master and update it.

@jonbullock
Copy link
Member

👍

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

Successfully merging this pull request may close these issues.

None yet

3 participants