reactjs - 无法在 Gatsby JS 上从 GraphQL 查询超链接
问题描述
我正在写一个关于 Gatsby JS 的博客,但我遇到了超链接问题,我无法解决它。
我有以下查询
const options = {
renderNode: {
"embedded-asset-block": (node) => {
const alt = node.data.target.fields.title['es']
const url = node.data.target.fields.file['es'].url
return <img alt={alt} src={url} />
},
[INLINES.HYPERLINK]: (node) => {
if(node.data.uri.indexOf('youtube.com') !== -1){
return(
<iframe width="560" height="315" src={node.data.uri} frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
)
}else{
return(
<a href={node.data.uri}>{node.content.value}</a>
)
}
}
}
}
通过这个查询,我可以添加资产和 youtube 视频。问题是,当我添加超链接时,它们会显示在页面上但没有文本。
我只看到<a href="https://www.test.es"></a>
这个链接的而不是文本。
我知道问题出在这里<a href={node.data.uri}>{node.content.value}</a>
,但我无法查询该值。
这是 GraphQL:
"body": {
"json": {
"nodeType": "document",
"data": {},
"content": [
{
"nodeType": "paragraph",
"content": [
{
"nodeType": "text",
"value": "Desde ",
"marks": [],
"data": {}
},
{
"nodeType": "hyperlink",
"content": [
{
"nodeType": "text",
"value": "FelixDigital",
"marks": [],
"data": {}
}
我需要查询值(FelixDigital)
有人可以帮助我吗?
太感谢了,
解决方案
Can you do a debugger inside this code?
It's hard to say.. but what I would check is the value of node
. To me it looks like content is an array and inside the first item of the array you have value so to me it should look more like node.content[0].value
.
推荐阅读
- knex.js - 如何通过 knex.js 选择 json mssql?
- c# - 升级到 .Net Framework 4.8 后,ClickOnce 部署变得流氓
- javascript - 使用不透明类型对 Typescript 记录进行索引
- python - Django 如何在页面周围移动文本
- c# - GetElementResult() null iText 7
- html - 无法让 html 在工作表的侧栏中呈现
- sql - 加入来自同一个表的 2 个选择查询
- ruby-on-rails - 仅对电子邮件禁用资产指纹识别?
- import - rust - 如何将文件夹中的文件导入到另一个文件夹中的文件中?
- vue.js - 分析一个 Vue Js 应用的加载时间