lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.88k stars 86 forks source link

page.search with `url` not working #533

Closed MichaelHirn closed 7 months ago

MichaelHirn commented 10 months ago

Version

2.0.1

Platform

mac

What steps will reproduce the bug?

  1. Target Page: create a page with custom url data attribute.
  2. Search Page: create another page that lists all pages via search.pages() (make sure rankingOrder is greater than the Target Page)

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

Search Page returns the Target Page

What do you see instead?

Search Page does not find or return Target Page. No error or warning is raised either.

Additional information

No response

oscarotero commented 10 months ago

@MichaelHirn What's the custom url that you want to assign?

search.pages() only returns HTML pages. This means the url must end with .html or / (which is equivalent to /index.html).

For example: /pathname is a non-HTML page, it's just a file without extension. But /pathname/ is a HTML page because is exported to /pathname/index.html.

MichaelHirn commented 10 months ago

Hey @oscarotero - that explains it then. I had a posts/2023-12-01-daily.md page with date field like this

---
url: ./custom-post-url
---

I have since moved away from the -daily slugs in the file name to posts/2023-12-01-custom-post-url.md and got rid of the url and it works. Judging by your answer I could probably keep it in the initial format and simple append .html to the url attribute value and it would also work?

oscarotero commented 10 months ago

You can append .html or /, depending on whether you prefer pretty urls or not. For example:

---
url: ./custom-post-url/
---

But in Lume 2, you have the variable basename that is used to change the name of the file without worrying about extensions or pretty url configurations, so it's easier to do simply:

---
basename: custom-post-url
---