对于有使用contentful.com API经验的人,我正在尝试按字段名称进行查询和排序,并且当前获得"ServerError".针对其示例API生成的查询示例(使用"fields.name"作为参数):
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=fields.name&access_token=b4c0n73n7fu1
请注意,如果使用"sys.createdAt",它可以正常工作......
https://cdn.contentful.com/spaces/cfexampleapi/entries?order=sys.createdAt&access_token=b4c0n73n7fu1
文档非常模糊(https://www.contentful.com/developers/documentation/content-delivery-api/javascript/#search-order),我搜索了很长时间的例子/样本,但无济于事.
提前感谢任何想法/想法!
我正在评估Contentful.com作为Angular SPA的内容引擎.
我面临的问题是按内容类型检索条目(例如,获取"博客"类型的所有条目).如文档示例中所述,这可以通过以下方式完成:
/ spaces/spaceid/entries?access_token = token&content_type = cat
所以在我的情况下而不是"cat",content_type ="blog"或content_type ="news"将是我期望互动的方式.
我面临的现实是通过content_type检索事物不会让我使用我的内容类型的名称 - 它期望ID是一个丑陋的GUID,所以我的查询看起来像这样:
/ spaces/spaceid/entries?access_token = token&content_type = 2wKn6yEnZewu2SCCkus4as
这样做的麻烦是:
我目前唯一能看到的解决方案是在页面加载时预先检索内容类型到id映射并使用它 - 但它对性能的影响不大.
文档似乎总是使用友好可读的内容类型ID(例如cat),但这不是我的经验.
所以,为了解决这个问题,有:
我正在尝试在我当前的项目中使用Contentful,我正在尝试了解如何根据链接对象中的字段过滤我的查询结果.
我的顶级对象包含一个定义如下的链接:
"name": "Service_Description",
"fields": [
{
"name": "Header",
"id": "header",
"type": "Link",
"linkType": "Entry",
"required": true,
"validations": [
{
"linkContentType": [
"offerGeneral"
]
}
],
"localized": false,
"disabled": false,
"omitted": false
},
Run Code Online (Sandbox Code Playgroud)
此"标头"字段链接到具有此定义的另一种内容类型:
"fields": [
{
"name": "General",
"id": "general",
"type": "Link",
"linkType": "Entry",
"required": true,
"validations": [
{
"linkContentType": [
"genericGeneral"
]
}
],
"localized": false,
"disabled": false,
"omitted": false
},
Run Code Online (Sandbox Code Playgroud)
然后链接到最低级别:
"fields": [{
"name": "TagList",
"id": "tagList",
"type": "Array",
"items": {
"type": "Link",
"linkType": "Entry",
"validations": [ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Angular 6 设置 PWA,但无法让 Service Worker 离线提供内容。我尝试了很多配置和东西几天了,但没有成功。
Service Worker 似乎已注册并且在 Chrome 的审计选项卡中运行灯塔通过了 pwa 测试。
我正在使用 Contentful 为该站点提供文本/资产。Service Worker 正在从 dataGroups 中获取内容,但在 Service Worker 进行获取时返回 204 代码。我只能假设这会导致缓存存储为空。
但话又说回来,我希望灯塔测试失败,因为它不提供离线内容。我认为这是因为只要会话没有改变,页面就可以脱机工作。这意味着如果我关闭网络连接,它会在我从一条路线导航到另一条路线时工作,但如果我重新加载/打开新标签页/重新打开浏览器,则会失败并显示 504 代码。
我在本地 IIS 下托管 Angular 6 应用程序。
索引.html:
<base href="/servicemanager/">
Run Code Online (Sandbox Code Playgroud)
网络配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/servicemanager/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
ngsw-config.json:
"dataGroups": [
{ …Run Code Online (Sandbox Code Playgroud) service-worker contentful progressive-web-apps angular angular-service-worker
我正在使用 gatsbyJS 和 contentful。当我开始查询任何内容丰富的内容时,我没有得到 graphql 的支持。当我开始输入“allContentful*”时,不会出现任何内容:
\n\n\n\n当我进行查询时,查询有效。但下划线是红色的,我没有机会看到哪些类型可用:
\n\n\nContentful npm 包提供对 API 的所有功能的访问。就我而言,我知道所需条目的 ID,但需要检索非默认区域设置的数据,并且我看不到任何传递区域设置选项的方法。我的查询如下所示:
const { createClient } = require('contentful');
const contentfulClient = createClient({
accessToken: 'xxxxxxxx',
space: 'xxxxxxx',
});
const entry = contentfulClient
.getEntry('xxxxxx')
.catch(console.error);
Run Code Online (Sandbox Code Playgroud)
我知道我可以执行以下操作:
const data = await contentfulClient
.getEntries({
content_type: 'xxxxxx'
locale: 'cy',
'sys.id': xxxxx,
})
.catch(console.error);
const [entry] = data.items;
Run Code Online (Sandbox Code Playgroud)
但这需要内容类型并返回一个条目数组,当我知道我想要的确切条目时,这似乎违反直觉。我错过了什么吗?期望它做的事情似乎是合乎逻辑的。
我正在和Contentful一起玩!我在使用富文本内容字段时遇到问题。
我使用“@contentful/rich-text-types”和@contentful/rich-text-html-renderer模块来自定义此块的呈现方式,并显示富文本内容中链接的一些资源和参考。
在 nuxt asyncData 函数中调用 getEntries 后,我的页面组件中有一个可用的描述数据。我正在使用带有选项的 documentToHtmlString 函数。
一切工作正常,但我想使用我已经编写的组件(Post.vue),而不是在 ES6 模板字符串中返回模板。
我知道这是可能的,但我对 JS 世界还很陌生。
我尝试要求 Components/post/Post.vue,但我不知道如何使用它。
import { BLOCKS } from '@contentful/rich-text-types';
import { documentToHtmlString } from "@contentful/rich-text-html-renderer"
Run Code Online (Sandbox Code Playgroud)
渲染富文本字段的 Vue 组件模板
<section class="container">
<div class="columns">
<div class="column">
<div v-html="formatContent(description)" />
</div>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)
我只需调用 formatContent 方法来调用 documentToHtmlString,如下所示(它有效):
methods: {
formatContent(content) {
return documentToHtmlString(content, options)
}
}
Run Code Online (Sandbox Code Playgroud)
并使用文档中描述的选项自定义 documentToHtmlString:
const embeddedEntryRender = (node) => {
const { data: { target: entry} …Run Code Online (Sandbox Code Playgroud) 我有一个 Gatsby 网站,已经在线平稳运行了 3 个月。截至 7 月 24 日星期五,我开始收到以下结果,用户只能看到空白屏幕。
This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
at h (gatsby-browser-entry.js:77)
at O9Ll.t.default (buybike.js:52)
at Ki (react-dom.production.min.js:153)
at Fa (react-dom.production.min.js:175)
at vo (react-dom.production.min.js:263)
at cu (react-dom.production.min.js:246)
at ou (react-dom.production.min.js:246)
at Zo (react-dom.production.min.js:239)
at react-dom.production.min.js:123
at scheduler.production.min.js:19
Run Code Online (Sandbox Code Playgroud)
这是我的 package.json
"@reach/dialog": "^0.10.1",
"@reach/tabs": "^0.10.1",
"@reach/visually-hidden": "^0.10.1",
"@stripe/stripe-js": "^1.4.0",
"bootstrap": "^4.4.1",
"dotenv": "^8.2.0",
"gatsby": "^2.23.18",
"gatsby-background-image": "^1.1.1",
"gatsby-image": "^2.3.1",
"gatsby-plugin-create-client-paths": …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Contentful 获取富文本,但在 gatsby-source-contentful 的 4.x 版本中,文档似乎不再更新。它引用的是json,但它已更改为raw,这意味着我不知道如何进行。
这是我的代码:
import React from "react"
import { graphql, Link } from "gatsby"
import { documentToReactComponents } from "@contentful/rich-text-react-renderer"
import Layout from "../components/layout/layout"
import Img from "gatsby-image"
import SEO from "../components/layout/seo"
export const query = graphql`
query($slug: String!) {
contentfulBlogPost(slug: { eq: $slug }) {
title
publishedDate(formatString: "Do MMMM, YYYY")
featuredImage {
fluid(maxWidth: 750) {
...GatsbyContentfulFluid
}
}
body {
json
}
}
}
`
const BlogPost = props => {
const options = …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 Azure Static Web 应用程序发布 Gatsbyjs。我有一个插件(gatsby-source-contentful)。
我需要传递如下变量:
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
},
},
Run Code Online (Sandbox Code Playgroud)
错误:
Running 'npm run build'...
> gatsby-starter-default@0.1.0 build /github/workspace
> gatsby build
success open and validate gatsby-configs - 0.021s
error Invalid plugin options for "gatsby-source-contentful":
- "accessToken" is required
- "spaceId" is required
not finished load plugins - 0.905s
Run Code Online (Sandbox Code Playgroud)
我可以在哪里通过这个?
谢谢。
environment-variables node.js contentful gatsby azure-static-web-app
contentful ×10
gatsby ×4
javascript ×3
angular ×1
graphql ×1
netlify ×1
node.js ×1
nuxt.js ×1
reactjs ×1
vue.js ×1