Closed ndom91 closed 2 weeks ago
Manually writing it back out (storage.files.set
, like I found in the implementation for source.write
) also doesn't seem to work :thinking:
transformers: [
async ({ storage }) => {
// const releasesFile = storage.files.get("releases.page")
const releasesFile = storage.read("releases", "page")
if (!releasesFile) {
console.log("No releases file found")
return
}
// Fetch latest release from GitHub
const ghResponse = await fetch(
"https://api.github.com/repos/gitbutlerapp/gitbutler/releases/latest"
)
if (!ghResponse.ok) {
console.log(`Failed to fetch latest release: ${ghResponse.statusText}`)
return
}
const ghResponsePayload = await ghResponse.json()
const latestRelease = Array.isArray(ghResponsePayload)
? ghResponsePayload[0]
: ghResponsePayload
if (latestRelease.draft || latestRelease.prerelease) {
console.log("Latest release is a draft or prerelease, skipping update")
return
}
// @ts-expect-error TODO type data
const newContent = releasesFile.data.data.exports.structuredData.contents
newContent.splice(1, 0, {
heading: `v${latestRelease.name.replace("release/", "")}`,
content: latestRelease.body
})
// @ts-expect-error TODO type data
releasesFile.data.data.exports.structuredData.contents = newContent
↪️ // Both of these don't seem to work
storage.write("releases.mdx", "page", releasesFile.data)
storage.files.set("releases.page", releasesFile);
}
],
I can only imagine that the structuredData
object is not where new content should go, but I can't gleam where else it should be inserted
Hmm are you trying to insert a entry to structured data? In this case you can modify the output instead of using a storage transformer. Also structured data is for implementing document search, you should use something else, like server components for auto-generated content
Yeah maybe I'm using the wrong tool for the job. Like I mentioned above, my goal is to dynamically insert some content (a string of markdown formatted copy) into a pre-existing markdown file (/docs/content/release.mdx
) during build.
What do you mean specifically by "modify the output instead of using a storage transformer"? Where would I do that?
If you want to modify the structured data, add:
getPages().forEach(page => {
page.exports.structuredData = ...
})
Instead.
my goal is to dynamically insert some content (a string of markdown formatted copy) into a pre-existing markdown file (/docs/content/release.mdx) during build.
Use a Server Component to insert content dynamically
To Reproduce
So my goal is to take our
releases.mdx
page and on build, fetch the latest releases from the GH API and preppend the latest release markdown body to thatreleases.mdx
page.I very well may be doing it wrong, but here's what I've got. My
source.ts
:In the
transformers[0]
I'm doing:releases.mdx
pageconst releasesFile = storage.files.get("releases.page")
releasesFile.data.data.exports.structuredData.contents
arraystorage.write("releases.mdx", "page", releasesFile.data)
Current vs. Expected behavior
Current Behavior
The rendered
/releases
page only displays the markdown content in thereleases.mdx
file. None of the additional content from GH which I've written in via the sources API seems to appearExpected Behavior
Additional GitHub content appears in the rendered page
Provide environment information
Which area(s) are affected? (Select all that apply)
Core
Additional context
Using: