是否有任何简单的方法将markdown文本从contentful api转换为渲染为html代码以显示在html页面上.我尝试过使用pagedown和一些类似的技巧,但似乎没有一个对我有用.
gatsby: 2.20.8
gatsbh-source-contentful: 2.2.5
Run Code Online (Sandbox Code Playgroud)
我已经验证了我的spaceId
并且accessToken
是正确的,并且我已经验证了这些密钥可以访问我的 Contentfuldevelopment
环境。我试过了:
GATSBY_CONTENTFUL_OFFLINE
.cache
目录environment
为“master”并完全删除它我不断收到此错误。有任何想法吗?
ERROR
Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.
Used options:
spaceId: "*********z1u"
accessToken: "*****************************************vMI'"
environment: "development"
host (default value): "cdn.contentful.com"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true
Run Code Online (Sandbox Code Playgroud)
这是我的代码 gatsby-config.js …
真的很难让这个工作.我在Contentful中设置了webhook定义.当我在Contentful中发布条目时,它会向webhooks.example.com发送HTTP POST请求.
在该子域我运行NodeJS服务器以接受请求.我查看了Contentful API文档,它说请求正文应该包含新发布的条目.
我已经尝试了两种接收请求的方法,这两种方法都没有给我任何请求体.首先,我尝试了contentful-webhook-server NPM模块:
var webhooks = require("contentful-webhook-server")({
path: "/",
username: "xxxxxx",
password: "xxxxxx"
});
webhooks.on("ContentManagement.Entry.publish", function(req){
console.log("An entry was published");
console.log(req.body);
});
webhooks.listen(3025, function(){
console.log("Contentful webhook server running on port " + 3025);
});
Run Code Online (Sandbox Code Playgroud)
这里请求来了,我得到了消息,An entry was published
但req.body
未定义.如果我这样做console.log(req)
,我可以看到完整的请求对象,它不包括正文.
所以我尝试运行一个基本的Express服务器来接受所有的POST请求:
var express = require("express"),
bodyParser = require("body-parser"),
methodOverride = require("method-override");
var app = express();
app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({extended:true}));
app.use(methodOverride("X-HTTP-Method-Override"));
app.post("/", function(req, res){
console.log("Incoming request");
console.log(req.body);
});
Run Code Online (Sandbox Code Playgroud)
再说一遍,我得到的Incoming request
消息 …
我看到如何通过ID查询条目.
有没有办法通过slug查找?这就是我真正想做的事情.
谢谢!
我正在使用 React 上下文来存储 NextJS 网站(例如 example.com/en/)的语言环境。设置如下所示:
组件/语言环境/index.jsx
import React from 'react';
const Context = React.createContext();
const { Consumer } = Context;
const Provider = ({ children, locale }) => (
<Context.Provider value={{ locale }}>
{children}
</Context.Provider>
);
export default { Consumer, Provider };
Run Code Online (Sandbox Code Playgroud)
页面/_app.jsx
import App, { Container } from 'next/app';
import React from 'react';
import Locale from '../components/Locale';
class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
const pageProps = Component.getInitialProps ? await Component.getInitialProps(ctx) : {}; …
Run Code Online (Sandbox Code Playgroud) 我在尝试打开通过 GitHub 分叉的项目时遇到以下错误。
success open and validate gatsby-configs - 0.492s
ERROR #11331 PLUGIN
Invalid plugin options for "gatsby-source-contentful":
- "accessToken" is required
not finished load plugins - 6.220s
Run Code Online (Sandbox Code Playgroud)
我已经进行了多次编辑,但无法处理该项目,因为我目前无法打开它。我确实有一个内容丰富的帐户,但对 Gatsby 相当陌生,并且不知道如何为accessToken
.
我需要通过 来执行此操作process.env
,还是我完全错过了该过程?
谢谢,如有任何帮助,我们将不胜感激。
我有以下富文本文档
{
"data":{},
"content":[
{
"data":{},
"content":[
{
"data":{},
"marks":[ ],
"value":"test",
"nodeType":"text"
}, {
"data":{},
"marks":[],
"value":"",
"nodeType":"text"
}
],
"nodeType":"paragraph"
},
{
"data":{
"target":{
"sys":{
"space":{
"sys":{
"type":"Link",
"linkType":"Space",
"id":"gedg1u5b0yz9"
}
},
"id":"2CzKe2pWvewCiek6w0yyoQ",
"type":"Asset",
"createdAt":"2019-01-07T22:37:55.473Z",
"updatedAt":"2019-01-07T22:37:55.473Z",
"environment":{
"sys":{
"id":"master",
"type":"Link",
"linkType":"Environment"
}
},
"revision":1,
"locale":"en-US"
},
"fields":{
"title":"Test Image",
"description":"Image for testing",
"file":{
"url":"//images.ctfassets.net/<hidden>/<hidden>/<hidden>/IMG_2878.JPG",
"details":{
"size":3874595,
"image":{
"width":5184,
"height":3456
}
},
"fileName":"IMG_2878.JPG",
"contentType":"image/jpeg"
}
}
}
},
"content":[],
"nodeType":"embedded-asset-block"
},
{
"data":{},
"content":[
{
"data":{},
"marks":[],
"value":"",
"nodeType":"text" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个查询来检索一个对象,该对象的属性linkedCards
包含具有不同模式的对象数组。
我有 3 种不同的模式(内置Contentful):
CardA 示例:
{
id: 42,
productName: 'Laptop',
price: 999
}
Run Code Online (Sandbox Code Playgroud)
CardB 示例:
{
id: 999,
title: 'Buy our refurbished Laptops today!'
}
Run Code Online (Sandbox Code Playgroud)
CardC 示例:
{
id: 100,
linkedCards: [
{
id: 42,
productName: 'Laptop',
price: 999
},
{
id: 999,
title: 'Buy our refurbished Laptops today!'
}
]
}
Run Code Online (Sandbox Code Playgroud)
询问:
allCardC() {
nodes {
linkedCards {
id
title
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行以下 GraphQL 查询时,我得到
"Cannot query field "title" on type "CardACardBUnion". Did …
我有一个Gatsby项目,它有两个不同类型的内容非常相似的GraphQL查询:常规页面和维基文章.
页面由slug
export const query = graphql`
query($slug: String!) {
page: contentfulPage(slug: {eq: $slug}) {
title
slug
body {
remark: childMarkdownRemark {
excerpt
html
headings {
value
depth
}
}
}
updatedAt(formatString: "D. MMM YYYY")
authors {
name
email
}
}
}
`
Run Code Online (Sandbox Code Playgroud)
由slug撰写的Wiki文章
export const query = graphql`
query($slug: String!) {
article: contentfulWikiArticle(slug: {eq: $slug}) {
title
slug
body {
remark: childMarkdownRemark {
excerpt
html
headings {
value
depth
}
}
}
updatedAt(formatString: "D. MMM YYYY")
authors {
name …
Run Code Online (Sandbox Code Playgroud) 我认为这是一个非常普通的问题,但我在谷歌上找不到任何东西。
我正在学习 NextJs(使用 TypeScript)并且我有一个站点成功地使用动态路由、SSR 和增量再生,所有设置和部署到 Vercel。这是我的动态路由处理程序中的GetStaticProps
和GetStaticPaths
代码示例:
export const getStaticPaths: GetStaticPaths = async () => {
const routes = new CmsHelper().GetRoutes();
const paths = (await routes).items.map((item, index, items) => {
return item.fields.urlPath;
})
return {
paths: paths,
fallback: 'blocking',
};
}
export const getStaticProps: GetStaticProps = async (context) => {
const urlParts = context.params?.url as string[] || [];
const urlPath = `/${urlParts.join('/')}`;
const article = await new CmsHelper().GetArticle(urlPath);
return {
props: {
article
},
revalidate: 10,
} …
Run Code Online (Sandbox Code Playgroud) contentful ×10
gatsby ×4
graphql ×2
javascript ×2
next.js ×2
reactjs ×2
access-token ×1
dry ×1
express ×1
graphql-js ×1
localization ×1
markdown ×1
node.js ×1
typescript ×1
webhooks ×1