盖茨比:将博客文章的URL从索引更改为`/blog`
我是《盖茨比》的新手,我正在与《盖茨比幽灵启动器》合作。我有一个鬼博客设置和工作,但开箱即用,它显示在索引页上的博客文章。我想让我的网站在盖茨比:将博客文章的URL从索引更改为`/blog`,url,routes,gatsby,blogs,ghost-blog,Url,Routes,Gatsby,Blogs,Ghost Blog,我是《盖茨比》的新手,我正在与《盖茨比幽灵启动器》合作。我有一个鬼博客设置和工作,但开箱即用,它显示在索引页上的博客文章。我想让我的网站在/blog上显示博客文章 我似乎不知道如何移动博客帖子的url 这是我的gatsby节点文件: const path = require(`path`) const { postsPerPage } = require(`./src/utils/siteConfig`) const { paginate } = require(`gatsby-awesome-
/blog
上显示博客文章
我似乎不知道如何移动博客帖子的url
这是我的gatsby节点
文件:
const path = require(`path`)
const { postsPerPage } = require(`./src/utils/siteConfig`)
const { paginate } = require(`gatsby-awesome-pagination`)
const config = require(`./gatsby-config`)
/**
* Here is the place where Gatsby creates the URLs for all the
* posts, tags, pages and authors that we fetched from the Ghost site.
*/
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const result = await graphql(`
{
allGhostPost(sort: { order: ASC, fields: published_at }) {
edges {
node {
slug
}
}
}
allGhostTag(sort: { order: ASC, fields: name }) {
edges {
node {
slug
url
postCount
}
}
}
allGhostAuthor(sort: { order: ASC, fields: name }) {
edges {
node {
slug
url
postCount
}
}
}
allGhostPage(sort: { order: ASC, fields: published_at }) {
edges {
node {
slug
url
}
}
}
}
`)
// Check for any errors
if (result.errors) {
throw new Error(result.errors)
}
// Extract query results
const tags = result.data.allGhostTag.edges
const authors = result.data.allGhostAuthor.edges
const pages = result.data.allGhostPage.edges
const posts = result.data.allGhostPost.edges
// Load templates
const indexTemplate = path.resolve(`./src/templates/index.js`)
const blogTemplate = path.resolve(`./src/templates/blog.js`)
const tagsTemplate = path.resolve(`./src/templates/tag.js`)
const authorTemplate = path.resolve(`./src/templates/author.js`)
const pageTemplate = path.resolve(`./src/templates/page.js`)
const postTemplate = path.resolve(`./src/templates/post.js`)
// Create tag pages
tags.forEach(({ node }) => {
const totalPosts = node.postCount !== null ? node.postCount : 0
const numberOfPages = Math.ceil(totalPosts / postsPerPage)
// This part here defines, that our tag pages will use
// a `/tag/:slug/` permalink.
node.url = `/tag/${node.slug}/`
Array.from({ length: numberOfPages }).forEach((_, i) => {
const currentPage = i + 1
const prevPageNumber = currentPage <= 1 ? null : currentPage - 1
const nextPageNumber =
currentPage + 1 > numberOfPages ? null : currentPage + 1
const previousPagePath = prevPageNumber
? prevPageNumber === 1
? node.url
: `${node.url}page/${prevPageNumber}/`
: null
const nextPagePath = nextPageNumber
? `${node.url}page/${nextPageNumber}/`
: null
createPage({
path: i === 0 ? node.url : `${node.url}page/${i + 1}/`,
component: tagsTemplate,
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.slug,
limit: postsPerPage,
skip: i * postsPerPage,
numberOfPages: numberOfPages,
humanPageNumber: currentPage,
prevPageNumber: prevPageNumber,
nextPageNumber: nextPageNumber,
previousPagePath: previousPagePath,
nextPagePath: nextPagePath,
},
})
})
})
// Create author pages
authors.forEach(({ node }) => {
const totalPosts = node.postCount !== null ? node.postCount : 0
const numberOfPages = Math.ceil(totalPosts / postsPerPage)
// This part here defines, that our author pages will use
// a `/author/:slug/` permalink.
node.url = `/author/${node.slug}/`
Array.from({ length: numberOfPages }).forEach((_, i) => {
const currentPage = i + 1
const prevPageNumber = currentPage <= 1 ? null : currentPage - 1
const nextPageNumber =
currentPage + 1 > numberOfPages ? null : currentPage + 1
const previousPagePath = prevPageNumber
? prevPageNumber === 1
? node.url
: `${node.url}page/${prevPageNumber}/`
: null
const nextPagePath = nextPageNumber
? `${node.url}page/${nextPageNumber}/`
: null
createPage({
path: i === 0 ? node.url : `${node.url}page/${i + 1}/`,
component: authorTemplate,
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.slug,
limit: postsPerPage,
skip: i * postsPerPage,
numberOfPages: numberOfPages,
humanPageNumber: currentPage,
prevPageNumber: prevPageNumber,
nextPageNumber: nextPageNumber,
previousPagePath: previousPagePath,
nextPagePath: nextPagePath,
},
})
})
})
// Create pages
pages.forEach(({ node }) => {
// This part here defines, that our pages will use
// a `/:slug/` permalink.
node.url = `/${node.slug}/`
createPage({
path: node.url,
component: pageTemplate,
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.slug,
},
})
})
// Create post pages
posts.forEach(({ node }) => {
// This part here defines, that our posts will use
// a `/:slug/` permalink.
node.url = `/${node.slug}/`
createPage({
path: node.url,
component: postTemplate,
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.slug,
},
})
})
// Create pagination
paginate({
createPage,
items: posts,
itemsPerPage: postsPerPage,
component: blogTemplate,
pathPrefix: ({ pageNumber }) => {
if (pageNumber === 0) {
return `/`
} else {
return `/page`
}
},
})
}
const path=require(`path`)
const{postsPerPage}=require(`./src/utils/siteConfig`)
const{paginate}=require(`gatsby awesome pagination`)
const config=require(`./gatsby config`)
/**
*这里是盖茨比为所有的用户创建URL的地方
*我们从Ghost站点获取的帖子、标签、页面和作者。
*/
exports.createPages=异步({graphql,actions})=>{
const{createPage}=actions
常量结果=等待图形ql(`
{
allGhostPost(排序:{顺序:ASC,字段:published_at}){
边缘{
节点{
鼻涕虫
}
}
}
allGhostTag(排序:{顺序:ASC,字段:名称}){
边缘{
节点{
鼻涕虫
网址
后计数
}
}
}
allGhostAuthor(排序:{顺序:ASC,字段:名称}){
边缘{
节点{
鼻涕虫
网址
后计数
}
}
}
allGhostPage(排序:{顺序:ASC,字段:published_at}){
边缘{
节点{
鼻涕虫
网址
}
}
}
}
`)
//检查是否有任何错误
if(result.errors){
抛出新错误(result.errors)
}
//提取查询结果
const tags=result.data.allGhostTag.edges
常量authors=result.data.allghosauthor.edges
const pages=result.data.allGhostPage.edges
const posts=result.data.allGhostPost.edges
//加载模板
const indexTemplate=path.resolve(`./src/templates/index.js`)
const blogTemplate=path.resolve(`./src/templates/blog.js`)
const tagsTemplate=path.resolve(`./src/templates/tag.js`)
const authorTemplate=path.resolve(`./src/templates/author.js`)
const pageTemplate=path.resolve(`./src/templates/page.js`)
const postTemplate=path.resolve(`./src/templates/post.js`)
//创建标记页
tags.forEach(({node})=>{
const totalPosts=node.postCount!==null?node.postCount:0
const numberOfPages=Math.ceil(totalPosts/postsPerPage)
//这一部分定义了标签页将使用的
//a`/tag/:slug/`permalink。
node.url=`/tag/${node.slug}/`
Array.from({length:numberOfPages}).forEach((\ux,i)=>{
常数currentPage=i+1
const prevPageNumber=currentPage numberOfPages?null:currentPage+1
const previousPagePath=PreviousPageNumber
?prevPageNumber==1
?node.url
:`${node.url}page/${prevPageNumber}/`
:null
const nextPagePath=nextPageNumber
?`${node.url}页面/${nextPageNumber}/`
:null
创建页面({
路径:i==0?node.url:`${node.url}页面/${i+1}/`,
组件:tagsTemplate,
背景:{
//传递到上下文的数据可用
//作为GraphQL变量的页内查询。
slug:node.slug,
限制:postsPerPage,
跳过:我*后页,
numberOfPages:numberOfPages,
humanPageNumber:currentPage,
prevPageNumber:prevPageNumber,
nextPageNumber:nextPageNumber,
previousPagePath:previousPagePath,
nextPagePath:nextPagePath,
},
})
})
})
//创建作者页面
authors.forEach(({node})=>{
const totalPosts=node.postCount!==null?node.postCount:0
const numberOfPages=Math.ceil(totalPosts/postsPerPage)
//这一部分定义了作者页面将使用的
//一个`/author/:slug/`permalink。
node.url=`/author/${node.slug}/`
Array.from({length:numberOfPages}).forEach((\ux,i)=>{
常数currentPage=i+1
const prevPageNumber=currentPage numberOfPages?null:currentPage+1
const previousPagePath=PreviousPageNumber
?prevPageNumber==1
?node.url
:`${node.url}page/${prevPageNumber}/`
:null
const nextPagePath=nextPageNumber
?`${node.url}页面/${nextPageNumber}/`
:null
创建页面({
路径:i==0?node.url:`${node.url}页面/${i+1}/`,
组件:authorTemplate,
背景:{
//传递到上下文的数据可用
//作为GraphQL变量的页内查询。
slug:node.slug,
限制:postsPerPage,
跳过:我*后页,
numberOfPages:numberOfPages,
humanPageNumber:currentPage,
prevPageNumber:prevPageNumber,
nextPageNumber:nextPageNumber,
previousPagePath:previousPagePath,
nextPagePath:nextPagePath,
},
})
})
})
//创建页面
pages.forEach(({node})=>{
//这一部分定义了,我们的页面