Внутренние ссылки не разрешаются правильно с замечанием и gatsbyjs

Я написал в Твиттере о недавнем сообщении в блоге в Твиттере и linkedin. я скопировал ссылку прямо из адресной строки, но ссылка разрешена на домашнюю страницу

Но когда я нажимаю на свой iphone, он переходит на домашнюю страницу

const _ = require('lodash')
const Promise = require('bluebird')
const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
const { blogPostPath } = require('./src/utils/url')

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions

  return new Promise((resolve, reject) => {
    const blogPost = path.resolve('./src/templates/blog-post.js')
    resolve(
      graphql(
        `
          {
            allMarkdownRemark(
              sort: { fields: [frontmatter___date], order: DESC }
              limit: 1000
            ) {
              edges {
                node {
                  fields {
                    slug
                  }
                  frontmatter {
                    title
                  }
                }
              }
            }
          }
        `
      ).then(result => {
        if (result.errors) {
          console.log(result.errors)
          reject(result.errors)
        }

        // Create blog posts pages.
        const posts = result.data.allMarkdownRemark.edges

        _.each(posts, (post, index) => {
          const previous =
            index === posts.length - 1 ? null : posts[index + 1].node
          const next = index === 0 ? null : posts[index - 1].node

          const path = blogPostPath(post.node.fields.slug)

          createPage({
            path,
            component: blogPost,
            context: {
              slug: post.node.fields.slug,
              previous,
              next,
            },
          })
        })
      })
    )
  })
}

exports.onCreateNode = ({ node, actions, getNode }) => {
  const { createNodeField } = actions

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: `slug`,
      node,
      value,
    })
  }
}

И мой blogPostPath выглядит так:

module.exports.blogPostPath = slug => {
  const date = slug.substr(0, 11).replace(/-/g, '/')
  const title = slug.substr(12).replace('/', '')

  console.log(`/blog${date}/${title}`)

  return `/blog${date}/${title}`
}

0 ответов

Другие вопросы по тегам