盖茨比:将博客文章的网址从索引更改为`/ blog`

问题描述

我是Gatsby的新手,正在与gatsby-ghost-starter合作。我已经建立并工作了一个Ghost博客,但是开箱即用的是它在索引页面显示博客文章。我想让我的网站在/blog显示博客文章

我似乎无法弄清楚如何移动博客文章的网址。

这是我的gatsby-node文件

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((_,component: authorTemplate,})
        })
    })

    // 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,})
    })

    // Create pagination
    paginate({
        createPage,items: posts,itemsPerPage: postsPerPage,component: blogTemplate,pathPrefix: ({ pageNumber }) => {
            if (pageNumber === 0) {
                return `/`
            } else {
                return `/page`
            }
        },})
}

我在“加载模板”下创建并导入了blog模板,但不确定将其放在何处。如何更改博客文章的网址以将其显示/blog而非首页上?

Here is the Github page of the starter I am using

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...