question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include file slug value in `Page.src` object

See original GitHub issue

Lume does some calculations behind the scenes to determine information about the source of a generated page. For example, given a file saved at /articles/2022-08-29_porto.md, Lume provides the following data in Page.src:

{
  path: "/articles/2022-08-29_porto",
  lastModified: 2022-10-01T17:46:49.762Z,
  created: 2022-10-01T17:16:39.480Z,
  remote: undefined,
  ext: ".md"
}

Lume will also add a page.data.data value if the base file name contains YYYY-MM-DD_ (so for the above this would be calculated to be 2022-10-01T00:00:00.000Z).

However, there is one other piece of information that may be useful to site authors: the file slug. In the case of the above, this value would be porto.

This value could be used in url() functions:

export function url(page) {
  return `./example/${page.src.fileSlug}/`;
}

It could also be used by page (pre)processors. This is my use case, where I am currently having to calculate this value myself to generate a new URL.

(Eleventy provides a similar fileSlug value).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
oscaroterocommented, Nov 3, 2022

This will be available in Lume 1.13.0. Closing this.

1reaction
paulrobertlloydcommented, Oct 4, 2022

Thanks for this, that works for now (bit better than my regex!)

I do think this value should be exposed somewhere, after all it’s a user defined piece of data, much like the date in the file name.

I wouldn’t mind this value being provided as a default value for page.data.slug, or even page.src.path, but you have a better idea of the overall architecture and project direction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Include file slug value in `Page.src` object - PullAnswer
You can get the file path without the date in page.dest.src . To set a Url based on the slug value, you can...
Read more >
How to get slug value in getStaticProps to call api with ...
You can get the slug value in getStaticProps and use it to call api based on slug export async function getStaticPaths() { const...
Read more >
How to Convert Title to URL Slug using JavaScript
Given a title and the task is to convert title into URL slug using JavaScript. In this article, we will use HTML to...
Read more >
How do I retrieve the slug of the current page?
Save this question. Show activity on this post. I am trying to retrieve the slug of the current WordPress page outside the loop....
Read more >
Using Page Slugs
Slugs in URLs​​ With a slug value, the 'Scone' thing becomes this: With Slugs, anything can have its own custom URL making them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found