Skip to content

How to get the source path from a page? #96

Answered by valtlai
valtlai asked this question in Q&A
Discussion options

You must be logged in to vote

Found a solution. Is this the best approach?

In _data/site.yml, I have:

repoUrl: https://github.com/valtlai/valtlai.fi/blob/main

In _config.js:

site.preprocess([".html"], (page) => {
  page.data.srcUrl = page.src.path + page.src.ext;
});

In a layout file:

<a href="{{ site.repoUrl }}{{ srcUrl }}">View source</a>

Replies: 1 comment 1 reply

Comment options

valtlai
May 20, 2021
Collaborator Author

You must be logged in to vote
1 reply
@oscarotero
Comment options

Answer selected by valtlai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants