Я создал блог, используя стартовый шаблон Гэтсби. Прямо сейчас, когда я открываю статью, URL-адрес, который она показывает, - http://localhost:8000/JavaScript:%20Behind%20The%20Scenes/
. Я посмотрел этот ответ и изменил свойство path
, но тогда страница не загружалась, она просто показывала пустую страницу с таким же URL-адресом. Я не знаю, почему он добавляет % 20 в путь.
Примечание : путь на самом деле является именем папки. Например, в каталоге /content/blog/JavaScript:Behind The Scenes/index.md
путь, который идет в URL, фактически является именем папки. Я не знаю почему. Путь должен был быть названием, которое я написал в index.md
этой папки.
index.md
---
title: 'The Execution Context'
date: '2020-02-16'
category: "JavaScript"
---
Blog Content..............
gatsby- node.js
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve(`./src/templates/blog-post.js`)
return graphql(
`
{
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
title
category
}
}
}
}
}
`
).then(result => {
if (result.errors) {
throw result.errors
}
// Create blog posts pages.
const posts = result.data.allMarkdownRemark.edges.filter(
({ node }) => !!node.frontmatter.category
)
posts.forEach((post, index) => {
const previous = index === posts.length - 1 ? null : posts[index + 1].node
const next = index === 0 ? null : posts[index - 1].node
createPage({
path: post.node.fields.slug,
component: blogPostTemplate,
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,
})
}
}
Кроме того, у меня есть некоторые проблемы со ссылками на Github и Twitter. Когда я нажимаю на них, отображается страница, которая не найдена. Показывает странный URL: https://github.com/https://github.com/myGithubName
https://twitter.com/https://twitter.com/myTwitterName
Я проверил, где это находится и выяснил:
gatsby-meta-config. js
module.exports = {
title: `My Blog`,
description: `Blog posted about ...`,
author: `myName`,
introduction: `I explain with words and code.`,
siteUrl: `https://gatsby-starter-bee.netlify.com`, // Your blog site url
social: {
twitter: `https://twitter.com/myTwitterName`, // Your Twitter account
github: `https://github.com/myGithubName`,
medium: ``,
facebook: ``
},
icon: `content/assets/profile.jpeg`, // Add your favicon
keywords: [`blog`],
comment: {
disqusShortName: '', // Your disqus-short-name. check disqus.com.
utterances: 'JaeYeopHan/gatsby-starter-bee', // Your repository for archive comment
},
configs: {
countOfInitialPost: 10, // Config your initial count of post
},
sponsor: {
buyMeACoffeeId: 'jbee',
},
share: {
facebookAppId: '', // Add facebookAppId for using facebook share feature v3.2
},
ga: '', // Add your google analytics tranking ID
}
Ссылки кажутся правильными в gatsby-meta-config.js
.