Skip to content

Instantly share code, notes, and snippets.

@dylsteck
Created February 10, 2023 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylsteck/4b2e7e72457e9d5f94e31a8c29a57d09 to your computer and use it in GitHub Desktop.
Save dylsteck/4b2e7e72457e9d5f94e31a8c29a57d09 to your computer and use it in GitHub Desktop.
Get article files from a repo with a folder named "Articles"
const { repository } = await octokit.graphql(`
query ($owner: String!, $name: String!){
repository(owner: $owner, name: $name) {
name
object(expression: "HEAD:") {
... on Tree {
entries {
name
type
mode
object {
... on Tree {
entries{
name
path
object {
... on Blob{
text
commitUrl
}
}
}
}
}
}
}
}
}
}`,
{owner: "YOUR_GH_USERNAME", name: "YOUR_REPO_NAME"});
const repoContent = repository.object.entries
// Assuming your articles folder is called 'Articles'
const articles = repoContent.find(repo => repo.name === 'Articles')
const articleEntries = articles.object.entries
// gets the slugs for each article
// used in `getStaticPaths`
const slugs = articleEntries.map((entry) => {
return { params: { id: `${matter(entry.object.text).data.slug}` } }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment