-
-
Save dylsteck/4b2e7e72457e9d5f94e31a8c29a57d09 to your computer and use it in GitHub Desktop.
Get article files from a repo with a folder named "Articles"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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