我看到我可以include:2使用node.js javascript api在getEntries方法中传递查询对象.如何通过getEntry返回单个对象的调用来实现.
// how do I get the nested objects by passing the parameter include:1
client.getEntry('<entry_id>', {<what goes here?>})
.then(function (entry) {
// logs the entry metadata
})
Run Code Online (Sandbox Code Playgroud) 我使用了这个教程:https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/environment-variables.md
我遵循的步骤:
1)安装dotenv@4.0.0
2)在根文件夹中创建两个文件:".env.development"和".env.production"
3)"按照他们的设置说明"(dotenv npm docs上的示例)
在gatsby-config.js:
const fs = require('fs');
const dotenv = require('dotenv');
const envConfig =
dotenv.parse(fs.readFileSync(`.env.${process.env.NODE_ENV}`));
for (var k in envConfig) {
process.env[k] = envConfig[k];
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我跑步时gatsby develop,NODE_ENV尚未设定:
error Could not load gatsby-config
Error: ENOENT: no such file or directory, open 'E:\Front-End Projects\Gatsby\sebhewelt.com\.env.undefined'
Run Code Online (Sandbox Code Playgroud)
它在我手动设置时有效:
dotenv.parse(fs.readFileSync(`.env.development`));
Run Code Online (Sandbox Code Playgroud)
我需要gatsby-config中的环境变量,因为我将敏感数据放在这个文件中:
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: envConfig.CONTENTFUL_SPACE_ID,
accessToken: envConfig.CONTENTFUL_ACCESS_TOKEN
}
}
Run Code Online (Sandbox Code Playgroud)
如何使它工作?
PS:附加问题 - 因为这让我想到,我知道我不应该在github上放置密码和令牌,但是当从github构建netlify时,还有其他安全方法吗?
我是vue.js的新手。我有一个简单的index.vue,它试图连接到内容丰富的目录并显示内容丰富的条目。我在index.vue中的代码如下所示:
<template>
<div>
<!-- render data of the person -->
<h1>{{ person.fields.name }}</h1>
<!-- render blog posts -->
<ul>
<li v-for="post in posts">
{{ post.fields.title }}
</li>
</ul>
</div>
</template>
<script>
import {createClient} from '~/plugins/contentful.js'
const client = createClient()
Run Code Online (Sandbox Code Playgroud)
但是,当我从浏览器尝试localhost:3000时,它返回以下错误:
./pages/index.vue模块错误(来自./node_modules/eslint-loader/index.js):
C:\ Users \ admin \ pdress \ pages \ index.vue 7:7错误迭代中的元素期望具有'v-bind:key'指令vue / require-v-for-key
?1个问题(1个错误,0个警告)
如果有人可以帮助我进一步进行vue.js的学习,我将不胜感激。提前致谢
我想弄清楚如何根据作者(参考)检索特定文章,我当前的功能检索所有文章,但我只想要作者特定的文章
const resp = yield client.getEntries({
'fields.insightsArticle': true,
'fields.excludeCountries[nin]': country,
'fields.publicationDate[lte]': moment(new Date()).toISOString(),
'fields.author.fields.firstname': author.firstName,
'fields.author.fields.lastname': author.lastName,
content_type: 'insight',
include: 2,
order: '-fields.publicationDate',
limit,
locale,
});
Run Code Online (Sandbox Code Playgroud)
我从 contentful 获得的当前日志是:“搜索参考文献时,您必须指定参考文献的内容类型。请发送内容类型 ID 作为查询参数”
我明白了,因为我将内容类型定义为洞察力。
欢迎任何建议!
我使用 contentful 作为我的移动应用程序的后端。
比赛装置存储在 contentful 中。我想查询下一场比赛,但出现以下错误:
422 (Unprocessable Entity)
Run Code Online (Sandbox Code Playgroud)
我检索下一个匹配项的函数:
function nextOpponent(){
var content_Type = mainConfig.config.contentType.match // Matches
var order = "fields.datum";
var gt = new Date().toLocaleString();
console.log(gt);
var query = "content_type=" + content_Type +
"&order=" + order +
"&fields.datum%5Bgte%5D=" + encodeURI(gt);
contentful.entries(query).then(
//success
function(response){
$scope.nextMatch = response.data.items[0];
console.log($scope.nextMatch);
},
//error
function(response){
}
)
}
Run Code Online (Sandbox Code Playgroud) 我在从 contentful 查询“长文本”类型的字段时遇到了问题。
我知道 Contentful 长文本字段实际上是降价。所以我安装了 gatsby-transformer-remark 插件,我认为我需要它。
这是我的 GraphQL 查询:
query getStoreById($relativeUrl: String!) {
contentfulStore(relativeUrl: { eq: $relativeUrl }) {
relativeUrl
shopPageTitle
mainPageTextContent {
mainPageTextContent
}
}
}
Run Code Online (Sandbox Code Playgroud)
控制台仍然显示:
Objects are not valid as a React child (found: object with keys {childMarkdownRemark}).
Run Code Online (Sandbox Code Playgroud)
与该错误消息有关。
谢谢!
当我尝试按照本教程进行操作时,出现以下错误:
哦,没有出什么问题:A response for the QueryOn<Thing> did return successfully, but a serious error occurred when decoding the array of Thing.
Double check that you are passing Thing.self, and references to all other EntryDecodable classes into the Client initializer.
当使用以下代码调用contentful时:
func fetch() {
let query = QueryOn<Thing>.where(field: .description, .exists(true))
client.fetchArray(of: Thing.self, matching: query) { (result: Result<ArrayResponse<Thing>>) in
switch result {
case .success(let things):
guard let firstThing = things.items.first else { return }
print(firstThing)
case .error(let error):
print("Oh no something …Run Code Online (Sandbox Code Playgroud) 我正在使用Gatbsy、Contentful CMS 和Netlify构建一个网站。它看起来很棒并且可以在本地运行,但是我在使用tracedSVG选项制作流体图像时遇到了问题。Netlify 部署曾经偶尔工作,当我向项目添加更多图像时,现在经常因以下错误而中断(并不总是在同一页面中):
10:53:45 AM: The GraphQL query from /opt/build/repo/src/pages/index.js failed.
10:53:45 AM: Errors:
10:53:45 AM: VipsJpeg: Corrupt JPEG data: premature end of data segment
10:53:45 AM: VipsJpeg: out of order read at line 544
10:53:45 AM: GraphQL request:54:3
10:53:45 AM: 53 | fragment GatsbyContentfulFluid_tracedSVG on ContentfulFluid {
10:53:45 AM: 54 | tracedSVG
10:53:45 AM: | ^
10:53:45 AM: 55 | aspectRatio
Run Code Online (Sandbox Code Playgroud)
或有时
error
The GraphQL query from /opt/build/repo/src/pages/index.js failed. …Run Code Online (Sandbox Code Playgroud) 我正在关注有关如何使用 Gatsby 实现 Contentful 的 RichText 字段类型的文档。
我的 GraphQL 查询只返回rawRichText 字段上的一个字段,名为synopsis:
query MyQuery {
allContentfulCountry {
edges {
node {
id
synopsis {
raw
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它返回:
{
"data": {
"allContentfulCountry": {
"edges": [
{
"node": {
"id": "fa07b3db-6acb-5b9a-7c4b-c42ef3c191b0",
"synopsis": {
"raw": "{\"data\":{},\"content\":[{\"data\":{},\"content\":[{\"data\":{},\"marks\":[],\"value\":\"The actual rich text...\",\"nodeType\":\"text\"}],\"nodeType\":\"paragraph\"}],\"nodeType\":\"document\"}"
},
"slug": "france"
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
文档假设documentToReactComponents(node.bodyRichText.json, options)但我无法访问json并且需要这样做:JSON.parse(country.synopsis.raw)
我错过了什么吗?
"@contentful/rich-text-react-renderer": "^14.1.2",
"@contentful/rich-text-types": "^14.1.2",
System:
OS: macOS 11.0.1 …Run Code Online (Sandbox Code Playgroud) (我认为这个问题可以概括为任何广泛使用的API,但我根据我实际使用的代码提出问题)
我们在控制器和视图中广泛使用Contentful Model,包括我们的布局.这意味着在我们访问(比如说)主页的任何功能测试中,我们的控制器操作将包括以下内容:
class HomepageController < ApplicationController
def homepage
# ... other stuff
@homepage_content = Homepage.find ('contentful_entry_id')
end
end
Run Code Online (Sandbox Code Playgroud)
...其中Homepage是ContentfulModel :: Base的子类,而@homepage_content将在视图中对其进行各种调用(有时会链接).在页脚中有一个类似的实例变量集并重复使用.
因此,对于功能测试,这是一个痛苦.我只想出两个选择:
要么
这两个(至少我正在做的方式)都有相当不好的缺点:
1)导致一堆测试kruft,每次我们添加或删除相关模型中的字段时都必须更新;
2)意味着我们为每个功能测试生成一个vcr yaml文件 - 每当我们更改测试的一个元素时我们必须记住清除相关的yml文件,这会改变它发送的请求
我错过了第三种选择吗?或者是否有一些明智的方法来做上述任何一种选择而不会遇到主要缺点?
contentful ×10
gatsby ×4
javascript ×3
graphql ×2
angularjs ×1
date ×1
fluid-images ×1
gatsby-image ×1
markdown ×1
netlify ×1
node.js ×1
reactjs ×1
rest ×1
stubbing ×1
swift ×1
vue.js ×1