Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Bugfix/relative links #127

Merged
merged 13 commits into from
Jul 27, 2020
Merged

Conversation

mattpolzin
Copy link
Contributor

@mattpolzin mattpolzin commented May 24, 2020

Fixes #126

When generating markdown, especially for use in GitHub, I like to rely on relative links as a robust way to link between documentation files living at file paths consistent relative to each other.

When I run the current GitHub Action, the default baseURL is used ("/"). This results in broken links between documentation files within GitHub or the GitHub Wiki.

I think this is partially solved by exposing the --base-url argument via the GitHub action (should this also default to "./" to coincide with the default format of .commonmark?).

That is only half the solution, though, because setting the baseURL to "./" results in Links prefixed with "/./". The solution to the second part of this appears to be straight forward enough, but time, experience, and feedback from maintainers will prove or disprove that!

This PR

  1. Exposes the base-url argument via the GitHub action. Defaults the GitHub action's base-url to "./". I think a relative URL works well more often than not for markdown, but I am not at all tied to this default because it also makes sense to use the same default the underlying program uses: "/".
  2. Uses URL for path append operation. Ostensibly, this simplifies the code and fixes my problem, but I don't know for sure that this works for all use-cases; I would love feedback on this decision.

I ran documentation generation with a few believable base urls to check some common cases. For a component named "A.B":

  1. "" -> [A.B](A_B)
  2. "/" -> [A.B](/A_B)
  3. "something" -> [A.B](something/A_B)
  4. "/something" -> [A.B](/something/A_B)
  5. "https://website.com/docs" -> [A.B](https://website.com/docs/A_B)
  6. "https://website.com/docs/" -> [A.B](https://website.com/docs/A_B)
  7. “./“ -> [A.B](./A_B)

@kongzii
Copy link

kongzii commented May 30, 2020

It would be great to get this merged. Currently, I have to fix links at Home.md after every auto-generation.

EDIT: And links in the Sidebar: https://github.com/SwiftDocOrg/swift-doc/wiki

kareman and others added 2 commits July 1, 2020 17:18
Fixes crashes like this one:

```bash
$ swift doc generate my-repo/Sources --module-name MyRepo
2020-06-30T17:00:13-0400 critical: Unable to construct path for /(lhs:rhs:) with baseURL /
Fatal error: file /private/tmp/swift-doc-20200630-24417-jrxtfw/Sources/swift-doc/Supporting Types/Page.swift, line 55
zsh: illegal hardware instruction  swift doc generate my-repo/Sources --module-name MyRepo
```
@mattpolzin
Copy link
Contributor Author

If anyone wants to temporarily switch to a fork, this fix has been working well for me for a while now. Just update your GitHub job as follows and you can change it back when the problem is fixed in this repo.

  ...
      - name: Generate Documentation
        uses: mattpolzin/swift-doc@bugfix/relative-links
  ...

@mattt
Copy link
Contributor

mattt commented Jul 15, 2020

@mattpolzin Thanks for submitting this, and sorry for not responding sooner. I'm taking a look now.

@mattpolzin mattpolzin requested a review from mattt July 25, 2020 02:58
Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw your latest changes, and am taking a look at this now. I'll probably write some tests to feel more confident in how this will work.

@mattt mattt merged commit 682f95d into SwiftDocOrg:master Jul 27, 2020
@mattt
Copy link
Contributor

mattt commented Jul 27, 2020

@mattpolzin @kareman Thank you both for your help in identifying and fixing this bug, and for your patience as I got this merged. I look forward to cutting a new release with this and other improvements this Friday.

@mattt mattt added this to the 1.0.0-beta.4 milestone Jul 27, 2020
kareman added a commit to kareman/Patterns that referenced this pull request Aug 13, 2020
kareman added a commit to kareman/Patterns that referenced this pull request Aug 13, 2020
* Wiki action: use SwiftDocOrg/swift-doc

SwiftDocOrg/swift-doc#127 has been merged.

* Enable manual launching.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Relative links are broken in markdown
4 participants