发布使用的相对 URL

当您撰写文章时,请使用相对路径,并让此插件重写路径以便于托管。

安装

要将其安装到您的 Publish 包中,请将其作为依赖项添加到您的 Package.swift 清单文件中

let package = Package(
  dependencies: [
    .package(
      name: "RelativeUrls",
      url: "https://github.com/markbattistella/relative-urls-publish-plugin",
      from: "1.0.0"
	)
  ],
  targets: [
    .target(dependencies: ["RelativeUrls"])
  ]
)

用法

管道

然后,该插件可以像这样在任何发布管道中使用

import RelativeUrls

try DeliciousRecipes().publish(using: [
  .installPlugin(.replaceRelativeUrls(site: Site))
])

您需要将 Website 传入插件参数。这样做是为了我们可以检查 URL 是本地的还是外部的。

Markdown

在编写 Markdown 文档时,您可以使用相对路径添加图像或锚点,而不是使用渲染后的路径。

图像

您可以访问 /Resources/,然后在路径之前访问,这样在其他代码编辑器(如 VSCode)中,自动完成功能将帮助您编写路径。

![alt text](/Resources/images/hero.jpg)

输出将是

![alt text](/images/hero.jpg)

锚点

您可以直接访问 /Content/ 目录及其中的所有文件。它支持 ID 标签,以便在支持的情况下跳转到标题。

[My First Post](/Content/posts/my-first-post.md)

[My First Post](/Content/posts/my-first-post.md#heading)

[External](https://markbattistella.com) 

输出将是

[My First Post](/posts/my-first-post/)

[My First Post](/posts/my-first-post/#heading)

[External](https://markbattistella.com)

贡献

我已经关闭了 Issues,如果您希望添加/更改代码库,请创建 Pull Request。

这样,每个人都可以让这些组件成长,并成为最好的,而不是等待我来编写它。

如何帮助

  1. 克隆仓库:git clone https://github.com/markbattistella/relative-urls-publish-plugin
  2. 创建您的功能分支:git checkout -b my-feature
  3. 提交您的更改:git commit -am 'Add some feature'
  4. 推送到分支:git push origin my-new-feature
  5. 提交 pull request