Skip to content

get static list of all markdown files #23

Answered by ElMassimo
jcalixte asked this question in Q&A
Discussion options

You must be logged in to vote

UPDATE: You can now useDocuments('~/posts').


Hi Julien! 😃

getLatestContent is a method that traverses the local filesystem to find all of the .mdx blog posts.

This part can be achieved using glob imports, as in the blog example:

const allPosts = import.meta.globEagerDefault('../pages/posts/**/*.{md,mdx}')

To get the latest, you can sort them by date. If you use date in frontmatter, have in mind that YAML supports Date objects so that you don't have to manually do new Date.

For the popular part, you could use fetch, query any APIs as needed to obtain the names or hrefs of the posts, and then pick the top 5 or sort them accordingly.


Currently îles does not polyfill fetch during SSG, but…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jcalixte
Comment options

@smakinson
Comment options

@ElMassimo
Comment options

@smakinson
Comment options

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