path: node.fields.slug, component: path.resolve('./src/templates/work.js'), context: { slug: node.fields.slug, }, }) }) } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 3...
createPage({ path: `/`, component: require.resolve('./src/templates/all-repositories.js'), context: { repositories } }); // Create a page for each repository. repositories.forEach(repository => { createPage({ path: `/repository/${repository.owner}/${repository.name}`, component: require...
你需要在src/templates目录下创建这个模板组件,并根据你的需求进行自定义。 最后,重新启动Gatsby开发服务器,你的多个页面将被创建并可以访问。 这是一个基本的示例,你可以根据自己的需求进行修改和扩展。关于Gatsby的更多信息和详细文档,请参考Gatsby官方网站。
假设我们的模板文件是src/templates/my-template.js,其中包含以下内容: 代码语言:txt 复制 import React from "react" const MyTemplate = ({ pageContext }) => { const { content } = pageContext return ( 动态设置的内容: {content} ) } export default MyTemplate 然后,在Gatsby的配置文件中,...
component: path.resolve('./src/templates/post.js'), context: { slug: node.childMarkdownRemark.fields.slug, }, }); }); }; 以为这会有用。我放的第二种类型确实有用。(在本例中,它创建post,但不创建集合。如果我颠倒调用createPages的顺序,它会交换,但它不会创建所有这些页面) ...
resolve(`./src/templates/post.js`), context: { // Data passed to context is available // in page queries as GraphQL variables. slug: node.fields.slug, }, }) }) } exports.onCreateNode = ({ node, getNode, actions }) => { console.log(node.internal.type) const { createNode...
Blog built by Gatsbyjs Framework + Style components - Blog-Gatsbyjs/posts/templates/UpdatePost.html at cd637d8529822746135d966371e7bda6264c2ed6 · amantiwari1/Blog-Gatsbyjs
amantiwari1/Blog-GatsbyjsPublic Notifications Fork0 Star2 Code Issues Pull requests Actions Projects Security Insights Files b2a56c3 .firebase posts __pycache__ data templates Copy2Markdown.js CreateCategory.html Createpost.html DeletePost.html ...
constpath =require("path")const_ =require("lodash")exports.createPages=({ actions, graphql }) =>{const{ createPage } = actionsconstblogPostTemplate = path.resolve("src/templates/blog.js")consttagTemplate = path.resolve("src/templates/tags.js")returngraphql(` ...
其中最为重要的是gatsby-node.js、/src/templates/blog-post.js以及gatsby-config.js。 gatsby-node.js 页面创建逻辑大部分都在gatsby-node.js,打开文件可以看到类似代码: // 页面创建函数 exports.createPages=({graphql,actions})=>{ const{createPage}=actions; ...