baseUrls,在 blogdown 中重定向和重写 [英] baseUrls, redirects and rewrites in blogdown

查看:55
本文介绍了baseUrls,在 blogdown 中重定向和重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好 blogdown stackoverflow 社区!

Hello blogdown stackoverflow community!

我最近一直在迁移我的个人 GitHub/Jekyll 博客(https://blogs.nopcode.org/brainstorm) 转到 Blogdown/Netlify,但我对 _redirectsconfig.toml url 路由业务有点困惑.

I have been recently migrating my personal GitHub/Jekyll blog (https://blogs.nopcode.org/brainstorm) over to Blogdown/Netlify, but I'm a bit confused by the _redirects and config.toml url routing business.

我已经详细阅读了官方 blogdown 和 netlify 文档.

I have read in detail the official blogdown and netlify documentations.

以及 Yihui 关于良好的永久链接卫生

不幸的是,无论我尝试了多少合理的更改(主要是在 config.toml_redirects 上),我都无法成功从 Jekyll 迁移,因为:

As well as Yihui's recommendations on good permalink hygiene

  1. 访问 https://blogs.nopcode.org/brainstorm 会导致所有博客文章链接呈现为https://blogs.nopcode.org/brainstorm/brainstorm/2017-09-01-blogpost-etc(URL 中有两个 brainstorm 而不是一个).我希望我所有的博文都链接到 https://blogs.nopcode.org/brainstorm/2017-09-01-blogpost-etc(只是一个头脑风暴).现在我正在做一个 URL 重写,这样当用户点击那些 brainstorm/brainstorm 链接之一时,它会被重写为简单的 brainstorm...显然不是最优的.
  2. 我必须在 static/brainstorm/ 下移动部分主题(js/images/css/etc..),以便加载主题资源并找到这些 URL.

Unfortunately, no matter how many sensible changes I try (essentially on config.toml and _redirects), I cannot successfully migrate from Jekyll since:

这是我博客的 repo,如果你发现它有明显的缺陷:

  1. Visiting https://blogs.nopcode.org/brainstorm results in all blogpost links rendered as https://blogs.nopcode.org/brainstorm/brainstorm/2017-09-01-blogpost-etc (two brainstorm's in the URL instead of just one). I would like all my blogposts to link to https://blogs.nopcode.org/brainstorm/2017-09-01-blogpost-etc (just one brainstorm). Right now I'm doing a URL rewrite so that when a user clicks on one of those brainstorm/brainstorm links, it gets rewritten as simply brainstorm... clearly suboptimal.
  2. I have to move parts of the theme (js/images/css/etc..) under static/brainstorm/ in order for theme assets to load and find those URLs.

https://github.com/brainstorm/brainblog

还有一连串的改变,我试图在没有太多扭曲的情况下追求可接受的配置:

https://github.com/brainstorm/brainblog

https://github.com/brainstorm/brainblog/commits/master

话虽如此,我发现 Hugo/blogdown 超级快,而且 RStudio 插件菜单/界面超级方便,可以快速更改博客文章:)

https://github.com/brainstorm/brainblog/commits/master

非常感谢!

推荐答案

这里的问题是因为 brainstorm 上的帖子有一个相对路径,而您将基本 url 设置为 https://blogs.nopcode.org/brainstorm

解决方案

Hugo 将根据主题配置构建您到 baseURL 的相对路径,Netlify 将发布相对于站点根目录的公共目录.

The issue here is created because there is a relative path to posts at brainstorm and you are setting your base url to https://blogs.nopcode.org/brainstorm

Hugo Server 在 brainstorm/brainstorm 中向您显示本地的正确链接,因为它根据 baseURL 配置路径.

Hugo will build your relative paths to the baseURL based on the theme configuration and Netlify will publish the public directory relative to the root of the site.

Netlify 路径来自已发布站点的根目录,并且不知道 Hugo 配置.在 Netlify 上,帖子的路径位于 /brainstorm.

Hugo Server is showing you the correct links locally at brainstorm/brainstorm, because it configures the paths based on the baseURL.

  • 为您网站的主页创建一个布局以创建列表,就像主题为某个部分所做的那样.

The Netlify paths are from the root of the published site and is unaware of the Hugo configuration. On Netlify, the path to the posts are at /brainstorm.

将所有帖子放入内容根目录并删除brainstorm文件夹

  • Create a layout for the home page of your site to create the list like the theme does for a Section.

content 文件夹的根目录下创建 _index.md 文件,其中包含要在页面上使用的任何 frontmatter 数据(如果有).

Put all posts into the content root and remove the brainstorm folder

在项目存储库的根目录下创建一个 layouts/index.html 文件.

Create _index.md file at the root of the content folder with any frontmatter data you want to use on the page, if any.


</main>{{ 部分footer.html".}}

{{ partial "header.html" . }} <main class="content" role="main"> <div class="archive"> {{ range .Data.Pages.GroupByDate "2006" }} <h2 class="archive-title">{{ .Key }}</h2> {{ range .Pages }} <article class="archive-item"> <a href="{{ .RelPermalink }}" class="archive-item-link">{{ .Title }}</a> <span class="archive-item-date"> {{ .Date.Format "2006/01/02" }} </span> </article> {{ end }} {{ end }} </div> </main> {{ partial "footer.html" . }}

这篇关于baseUrls,在 blogdown 中重定向和重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆