无法使用 next-mdx-remote 从 github 存储库获取 mdx 文件

问题描述 投票:0回答:1

开始开发新网站。想要使用mdx实现一个wiki页面,但要点是mdx文件必须在github上。使用 Next.js 站点指南从 github 请求文件时,出现错误。尝试使用 next-mdx-remote 获取文件。

import { CustomMDX } from "@/components/mdx-remote"

export const metadata = {
  title: 'Wiki• CodeCraft',
}

export default async function Wiki() {

  const res = await fetch('https://github.com/CodeCraft-Vanilla/wiki/blob/f6bd136f5f21e93daa17991371615889358aa06d/test.mdx', {cache: 'no-store'})
  const markdown = await res.text()


  return (
    <>
    <main className="pt-16">
    <CustomMDX
      source={markdown}
    />
    </main>
    </>
  )
}

这是我收到的错误:

Unhandled Runtime Error
Error: [next-mdx-remote] error compiling MDX:
Could not parse expression with acorn: Unexpected content after expression

> 1 | {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"pages","path":"pages","contentType":"directory"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"test.mdx","path":"test.mdx","contentType":"file"}],"totalCount":3}},"fileTreeProcessingTime":1.7504339999999998,"foldersToFetch":[],"reducedMotionEnabled":null,"repo":{"id":677950449,"defaultBranch":"main","name":"wiki","ownerLogin":"CodeCraft-Vanilla","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2023-08-13T07:23:58.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/142140962?v=4","public":true,"private":false,"isOrgOwned":true},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"f6bd136f5f21e93daa17991371615889358aa06d","listCacheKey":"v0:1691911438.0","canEdit":false,"refType":"tree","currentOid":"f6bd136f5f21e93daa17991371615889358aa06d"},"path":"test.mdx","currentUser":null,"blob":{"rawLines":["# Hello","","Wiki"],"stylingDirectives":[[{"start":0,"end":7,"cssClass":"pl-mh"},{"start":2,"end":7,"cssClass":"pl-en"}],[],[]],"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/CodeCraft-Vanilla/wiki/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null,"repoAlertsPath":"/CodeCraft-Vanilla/wiki/security/dependabot","repoSecurityAndAnalysisPath":"/CodeCraft-Vanilla/wiki/settings/security_analysis","repoOwnerIsOrg":true,"currentUserCanAdminRepo":false},"displayName":"test.mdx","displayUrl":"https://github.com/CodeCraft-Vanilla/wiki/blob/f6bd136f5f21e93daa17991371615889358aa06d/test.mdx?raw=true","headerInfo":{"blobSize":"14 Bytes","deleteInfo":{"deleteTooltip":"You must be signed in to make or propose changes"},"editInfo":{"editTooltip":"You must be signed in to make or propose changes"},"ghDesktopPath":null,"gitLfsPath":null,"onBranch":false,"shortPath":"fda4429","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FCodeCraft-Vanilla%2Fwiki%2Fblob%2Ff6bd136f5f21e93daa17991371615889358aa06d%2Ftest.mdx","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"3","truncatedSloc":"2"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplateHelpUrl":"https://docs.github.com/articles/about-issue-and-pull-request-templates","issueTemplate":null,"discussionTemplate":null,"language":"MDX","languageID":512838272,"large":false,"loggedIn":false,"newDiscussionPath":"/CodeCraft-Vanilla/wiki/discussions/new","newIssuePath":"/CodeCraft-Vanilla/wiki/issues/new","planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/CodeCraft-Vanilla/wiki/blob/f6bd136f5f21e93daa17991371615889358aa06d/test.mdx","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","dismissStackNoticePath":"/settings/dismiss-notice/publish_stack_from_file","releasePath":"/CodeCraft-Vanilla/wiki/releases/new?marketplace=true","showPublishActionBanner":false,"showPublishStackBanner":false},"renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"repoOwner":"CodeCraft-Vanilla","repoName":"wiki","showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","showDependabotConfigurationBanner":false,"actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":{"timedOut":false,"notAnalyzed":true,"symbols":[]}},"copilotInfo":null,"csrf_tokens":{"/CodeCraft-Vanilla/wiki/branches":{"post":"R9JxE9xMXVjoZLFVuLDJpXHIqc_u7yNLNqXapfQKSzb_F-ndhhT7smK3Rk7Mf9JQYDThOvGoh3K3EdTjy2XA3w"},"/repos/preferences":{"post":"8RE5VGmDQewAdOmVrDjOM42H6198-LZZfB6UVSTMiZmP-GTRIa1SlfVjkmMrN6Gufj2iYQeuPRS72-zcNI9inA"}}},"title":"wiki/test.mdx at f6bd136f5f21e93daa17991371615889358aa06d · CodeCraft-Vanilla/wiki"}
    |           ^

More information: https://mdxjs.com/docs/troubleshooting-mdx

在网上看到一些关于github token的内容,即使需要,你如何使用它们?

javascript next.js github-api
1个回答
0
投票

您正在获取的链接

https://github.com/CodeCraft-Vanilla/wiki/blob/f6bd136f5f21e93daa17991371615889358aa06d/test.mdx

从 github 获取整个 HTML 页面,而不仅仅是 Markdown。如果您想要文件的原始内容,而不需要其他内容,请使用

https://raw.githubusercontent.com/CodeCraft-Vanilla/wiki/f6bd136f5f21e93daa17991371615889358aa06d/test.mdx
© www.soinside.com 2019 - 2024. All rights reserved.