【发布时间】:2019-02-14 06:19:03
【问题描述】:
我无法使用 Gatsby 提取我的 Ghost 博客的数据。我使用 Ghost 作为我的后端,我使用一个包来获取 Ghost 博客作为源。问题只是在页面上获取单个帖子。这里是blog-post.js:
import React from "react";
export default ({ data }) => {
// const post = data.allGhostPost.edges;
return (
<div>
{/* <h1>{post.title}</h1> */}
{/* <div dangerouslySetInnerHTML={{ __html: post.html }} /> */}
</div>
);
};
export const query = graphql`
query BlogPostQuery($slug: String!) {
allGhostPost {
edges {
node {
id
slug
title
html
published_at
}
}
}
}
`;
这是我的 gatsby 节点文件:
exports.createPages = ({ graphql, boundActionCreators}) => {
const {createPage} = boundActionCreators
return new Promise((resolve, reject) => {
const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
resolve(
graphql(
`
{
allGhostPost(sort: { order: DESC, fields: [published_at] }) {
edges {
node {
id
slug
title
html
published_at
}
}
}
}
`
)
.then(result => {
result.data.allGhostPost.edges.forEach(edge => {
createPage({
path: edge.node.slug,
component: blogPostTemplate,
context: {
slug: edge.node.slug
}
})
})
return;
})
)
})
}
【问题讨论】:
-
我认为只要不向
allGhostPosts提供任何参数,查询确实有未使用的引用,因此是无效的。您是否尝试过完全删除“BlogPostQuery”的参数以及括号? -
是的,这行得通。可悲的是,它会返回所有帖子。当我需要蛞蝓提供给我的特定时。我是否没有在我应该的地方包括蛞蝓? @rm-