修改hexo+next, 使得url路径带.html后缀 部署到阿里云oss

您所在的位置:网站首页 plugin标签里的url 修改hexo+next, 使得url路径带.html后缀 部署到阿里云oss

修改hexo+next, 使得url路径带.html后缀 部署到阿里云oss

2023-04-14 19:45| 来源: 网络整理| 查看: 265

阿里云oss部署hexo不支持自动跳转到index.html页面,所以如果需要部署到阿里云oss上,那么需要做以下修改。

创建“标签”页面 生成 tags.html

新建“标签”页面

hexo new page tags 复制代码

给标签页面添加类型 我们在source文件夹中的tags文件夹下找到index.md文件,在它的头部加上type属性。

--- title: tags date: 2018-08-06 22:48:29 type: "tags" #新添加的内容 --- 复制代码

将index.md文件重命名为 tags.md并挪到 tags的父文件夹下,删除tags文件夹

创建“分类”页面 生成categories.html

这里和上一步骤基本一致

新建分类页面

hexo new page categories 复制代码

给分类页面添加类型 我们在source文件夹中的categories文件夹下找到index.md文件,在它的头部加上type属性。

--- title: 文章分类 date: 2017-05-27 13:47:40 type: "categories" #这部分是新添加的 --- 复制代码

将index.md文件重命名为 categories.md并挪到 categories的父文件夹下,删除categories文件夹

创建about.html

参考以上两个步骤

文章页面

在_config.yml中,修改

permalink: :year/:month/:day/:title/ 复制代码

permalink: post/:urlname.html 复制代码

其中 urlname为在文章中指定当前文件的永久链接,如

--- title: 修改hexo+next, 使得url路径带.html后缀 date: 2018-04-21 23:55:07 categories: [hexo设置] tags: [hexo] urlname: hexo-next-url-html-suffix --- 复制代码 修改文章归档首页的访问地址

修改 主题文件夹下的 _config.yml 配置文件

menu: home: / || home tags: /tags.html || tags categories: /categories.html || th archives: /archives/index.html || archive about: /about.html || user 复制代码

这里修改之后会出现 点击归档页菜单栏的时候 菜单没有处于选中状态

修改 主题文件夹下 scripts/helpers/engine.js

var current = this.url_for(canonical).replace('index.html', '', 'g'); 复制代码

var current = this.url_for(canonical); 复制代码

问题解决

修改hexo的分页 %d/index.html 变为 %d.html

hexo生成的分页 静态文件路径 如 archives/page/2/index.html 修改成 archives/page/2.html

修改 node_modules/hexo-pagination/lib/pagination.js

//var format = options.format || 'page/%d/'; var format = 'page/%d.html'; 复制代码 修改分页插件生成的分页链接

修改分页插件生成的分页链接 修改 node_modules\hexo\lib\plugins\helper\paginator.js

function link(i) { return self.url_for(i === 1 ? base + '/index.html' : base + format.replace('%d/', i) + '.html'); } 复制代码 修改分类页的链接 形如 categories/Spring-Cloud-%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/index.html

修改 node_modules\hexo\lib\plugins\helper\list_categories.js

const suffix = options.suffix || 'index.html'; 复制代码 修改标签页的链接 形如 tags/Spring-Cloud/index.html

修改 node_modules\hexo\lib\plugins\helper\tagcloud.js

result.push( `${transform ? transform(tag.name) : tag.name}` ); 复制代码 修改文章内容页里的 分类和标签 链接

修改 主题文件夹下 layout/_macro/post.swig

复制代码 # {{ tag.name }} 复制代码

到这里,所有的链接都是以 html后缀 打开



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3