1

在我的 Docusaurus 项目中,我的内部链接在我的本地环境中工作,但是当我推送到 GitLab 时,它们不再工作。它没有将原始文档标题替换为新标题,而是将其添加到最后的 url(' https://username.io/test-site/docs/overview/add-a-category.html ')。我查看了我的配置文件,但我不明白为什么会这样。

我尝试更新页面前面的 id,并确保它与 sidebars.json 文件中的 id 匹配。我还添加了 customDocsPath 并在配置文件中将其设置为“docs/”,尽管这应该是默认设置。

---
id: "process-designer-overview"
title: "Process Designer Overview"
sidebar_label: "Overview"
---
# Process Designer

The Process Designer is a collaborative business process modeling and 
design workspace for the business processes, scenarios, roles and tasks 
that make up governed data processes.

Use the Process Designer to:

 - [Add a Category](add-a-category.html)
 - [Add a Process or Scenario](Add%20a%20Process%20or%20Scenario.html)
 - [Edit a Process or Scenario](Edit%20a%20Process%20or%20Scenario.html)

我将括号中的添加类别链接更新为 md 扩展名,但这破坏了我本地的链接,它仍然无法在 GitLab 上运行。我希望当用户单击链接时,它将用新的文档标题(' https://username.gitlab.io/docs/add-a-category.html ')替换 url 中的文档标题它只是将它附加到最后(' https://username.gitlab.io/docs/process-designer-overview/add-a-category.html '),因此链接已断开,因为那不是文档所在的位置位于。

4

1 回答 1

2

我的链接有几个问题。首先,我使用 Pandoc 将这些文件从 html 转换为 markdown,并且没有添加前面的内容 - 而是依靠文件名将我的文件连接到侧边栏。这很好,除了几乎所有文件名中都有空格,您可以在上面的代码示例中看到。这导致了真正的问题,所以我找到了一个 Bash 脚本来用下划线替换我文件名中的所有空格,但现在我的所有链接都被破坏了。我使用代码编辑器中的搜索和替换更新了文件中的所有链接,将“%20”替换为“_”。我还需要用“.md”替换“.html”扩展名,否则我的项目将不再在本地工作。同样,我在代码编辑器中进行了搜索和替换。

最后,我最终添加了前面的内容,因为否则我的侧边栏标题都被下划线覆盖。由于我正在处理 90 个文件,因此我不想手动执行此操作。我找了一会儿,发现了thebearJew 的一个很好的要点,并对其进行了调整,以便它将文件名添加为 id,并将第一个标题添加为标题和 sidebar_label,因为它恰好适用于我们的项目。这是我在网上找到的 Bash 脚本,如果有兴趣,可以将文件名中的空格转换为下划线:

find $1 -name "* *.md" -type f -print0 | \
  while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done

如果其他人有类似的设置并且不想用前端更新大量文件,这是我最终得到的脚本:

# Given a file path as an argument
# 1. get the file name
# 2. prepend template string to the top of the source file
# 3. resave original source file

# command: find . -name "*.md" -print0 | xargs -0 -I file ./prepend.sh file

filepath="$1"
file_name=$("basename" -a "$filepath")

# Getting the file name (title)
md='.md'
title=${file_name%$md}
heading=$(grep -r "^# \b" ~/Documents/docs/$title.md)
heading1=${heading#*\#}

# Prepend front-matter to files
TEMPLATE="---
id: $title
title: $heading1
sidebar_label: $heading1
---
"
echo "$TEMPLATE" | cat - "$filepath" > temp && mv temp "$filepath"
于 2019-02-12T16:27:34.263 回答