- 48
- 0
我目前修改hexo的node_moduleshexolibpluginstag里的js文件。但出现了个问题。代码如下
module.exports = function(ctx) {
var Post = ctx.model('Post');
return function postLinkTag(args) {
var slug = args.shift();
if (!slug) return;
var post = Post.findOne({slug: slug});
if (!post) return;
var title = args.length ? args.join(' ') : post.title;
return '<a href="' + ctx.config.root + post.path + '" title="' + title + '"></a>'
};
};
代码如上,使用{% post_link 文件名 %}可直接获取标题为站内链接显示在文章内容里。我现在想在该链接下添加上该文章的内容。于是我添加了一句,post.content可以实现,可问题也出现了,在我每次hexo clean后,post.content就获取不到文章内容了。显示为undefined,而解决办法为必须删除或修改markdown里所有出现{% post_link %}的标签才可以正确获取post.content文章内容,请问这该如何解决呢?非常感谢!~
- 共 0 条
- 全部回答
-
SSD 普通会员 1楼
在Hexo中,可以通过以下步骤修改Node_modules中的文件,并获取文章内容:
-
打开你的Hexo项目目录,找到
/pages目录下的article目录。 -
在该目录下,创建一个名为
article.js的文件,其中包含以下内容:
javascript module.exports = { title: 'My First Article', path: '/articles/my-first-article', excerpt: 'This is the content of my first article. It describes the title and path of the article. This article is part of the ' + config.blog.name + ' blog series. You can find more articles in the blog directory.', meta: { description: 'Learn how to create a new article in Hexo. This article describes the steps to create a new article in Hexo, including the title, path, excerpt, and meta information.' }, content: [ { type: 'html', src: './content/my-first-article.html' } ] };在
content数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如html或markdown)。src:文章的内容,即文章的内容。
在
src字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
My First Article
This is the content of my first article. It describes the title and path of the article. This article is part of the [config.blog.name] blog series. You can find more articles in the blog directory. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。- 打开
/pages目录下的config文件,找到blog.yml文件,其中包含以下内容:
```yaml title: [Your Blog Name] description: A personal blog authors: [Your Author Name] categories: [Your Category Name] tags: [Your Tag Name]
posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html ```
在
config文件中,title字段定义了你的博客的名称,description字段定义了博客的描述,authors字段定义了博客的作者,categories字段定义了博客的分类,tags字段定义了博客的标签。在
posts数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如markdown或html)。path:文章的路径,即文章的URL路径。excerpt:文章的摘要,即文章的内容摘要。content:文章的内容,即文章的内容。
在
content字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
[Year] [Month] [Day] [Title]
- This is the content of the article.
- It is about [Article Topic].
- You can find more articles in the [blog directory]. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。-
打开
/pages目录下的pages目录,创建一个名为post/[year][month][day]的目录,用于存放你的文章。 -
在该目录下,创建一个名为
post/[year][month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你可以通过以下步骤在本地访问和编辑文章:
- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
posts目录下的content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你已经修改了
/pages目录下的article和config文件,可以通过以下步骤在本地访问和编辑文章:- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
-
-
久而旧之╮ 普通会员 2楼
在Hexo中,可以通过以下步骤修改Node_modules中的文件,并获取文章内容:
-
打开你的Hexo项目目录,找到
/pages目录下的article目录。 -
在该目录下,创建一个名为
article.js的文件,其中包含以下内容:
javascript module.exports = { title: 'My First Article', path: '/articles/my-first-article', excerpt: 'This is the content of my first article. It describes the title and path of the article. This article is part of the ' + config.blog.name + ' blog series. You can find more articles in the blog directory.', meta: { description: 'Learn how to create a new article in Hexo. This article describes the steps to create a new article in Hexo, including the title, path, excerpt, and meta information.' }, content: [ { type: 'html', src: './content/my-first-article.html' } ] };在
content数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如html或markdown)。src:文章的内容,即文章的内容。
在
src字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
My First Article
This is the content of my first article. It describes the title and path of the article. This article is part of the [config.blog.name] blog series. You can find more articles in the blog directory. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。- 打开
/pages目录下的config文件,找到blog.yml文件,其中包含以下内容:
```yaml title: [Your Blog Name] description: A personal blog authors: [Your Author Name] categories: [Your Category Name] tags: [Your Tag Name]
posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html ```
在
config文件中,title字段定义了你的博客的名称,description字段定义了博客的描述,authors字段定义了博客的作者,categories字段定义了博客的分类,tags字段定义了博客的标签。在
posts数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如markdown或html)。path:文章的路径,即文章的URL路径。excerpt:文章的摘要,即文章的内容摘要。content:文章的内容,即文章的内容。
在
content字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
[Year] [Month] [Day] [Title]
- This is the content of the article.
- It is about [Article Topic].
- You can find more articles in the [blog directory]. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。-
打开
/pages目录下的pages目录,创建一个名为post/[year][month][day]的目录,用于存放你的文章。 -
在该目录下,创建一个名为
post/[year][month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你可以通过以下步骤在本地访问和编辑文章:
- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
posts目录下的content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你已经修改了
/pages目录下的article和config文件,可以通过以下步骤在本地访问和编辑文章:- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
-
-
狐仙不是妖 普通会员 3楼
在Hexo中,可以通过以下步骤修改Node_modules中的文件,并获取文章内容:
-
打开你的Hexo项目目录,找到
/pages目录下的article目录。 -
在该目录下,创建一个名为
article.js的文件,其中包含以下内容:
javascript module.exports = { title: 'My First Article', path: '/articles/my-first-article', excerpt: 'This is the content of my first article. It describes the title and path of the article. This article is part of the ' + config.blog.name + ' blog series. You can find more articles in the blog directory.', meta: { description: 'Learn how to create a new article in Hexo. This article describes the steps to create a new article in Hexo, including the title, path, excerpt, and meta information.' }, content: [ { type: 'html', src: './content/my-first-article.html' } ] };在
content数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如html或markdown)。src:文章的内容,即文章的内容。
在
src字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
My First Article
This is the content of my first article. It describes the title and path of the article. This article is part of the [config.blog.name] blog series. You can find more articles in the blog directory. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。- 打开
/pages目录下的config文件,找到blog.yml文件,其中包含以下内容:
```yaml title: [Your Blog Name] description: A personal blog authors: [Your Author Name] categories: [Your Category Name] tags: [Your Tag Name]
posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html ```
在
config文件中,title字段定义了你的博客的名称,description字段定义了博客的描述,authors字段定义了博客的作者,categories字段定义了博客的分类,tags字段定义了博客的标签。在
posts数组中,每个元素是一个对象,包含以下字段:type:文章的类型,即文章的类型(如markdown或html)。path:文章的路径,即文章的URL路径。excerpt:文章的摘要,即文章的内容摘要。content:文章的内容,即文章的内容。
在
content字段中,你可以使用Markdown语法来编写文章内容,例如:```markdown
[Year] [Month] [Day] [Title]
- This is the content of the article.
- It is about [Article Topic].
- You can find more articles in the [blog directory]. ```
这将生成一个HTML文件,内容与
article.js文件中描述的内容相同。-
打开
/pages目录下的pages目录,创建一个名为post/[year][month][day]的目录,用于存放你的文章。 -
在该目录下,创建一个名为
post/[year][month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你可以通过以下步骤在本地访问和编辑文章:
- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
posts目录下的content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
现在,你已经修改了
/pages目录下的article和config文件,可以通过以下步骤在本地访问和编辑文章:- 打开终端(在Mac/Linux中是
Terminal,在Windows中是cmd或powershell)。 - 进入你的Hexo项目目录,例如:
cd /path/to/your/hexo/project- 打开
/pages目录下的config文件,例如:
cd /path/to/your/hexo/project/config- 在
blog字段中,将title字段的值更改为你希望的文章标题,例如:
yaml title: [Your Blog Name]- 在
description字段中,将你希望的文章描述的值更改为你希望的文章描述,例如:
yaml description: A personal blog- 在
authors字段中,将你希望的博客作者的值更改为你希望的博客作者,例如:
yaml authors: - [Your Author Name]- 在
categories字段中,将你希望的博客分类的值更改为你希望的博客分类,例如:
yaml categories: - [Your Category Name]- 在
tags字段中,将你希望的博客标签的值更改为你希望的博客标签,例如:
yaml tags: - [Your Tag Name]- 在
posts字段中,将你希望的content数组中的每个对象的type字段更改为markdown,例如:
yaml posts: - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the second article. content: - type: html src: ./content/[year][month][day].[title].html - type: markdown path: /articles/[year][month][day].[title].md excerpt: This is the content of the third article. content: - type: html src: ./content/[year][month][day].[title].html-
保存并关闭
config文件。 -
在
content目录下,创建一个名为year/[month][day]的目录,用于存放你的文章。 -
在
content目录下,创建一个名为year/[month][day].html的文件,内容与content数组中对应的文章内容相同。
-
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

