Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative Link Resolution does not work with baseURI with Subdirectory #147

Open
ahandsel opened this issue Oct 24, 2022 · 1 comment
Open

Comments

@ahandsel
Copy link

Hello, I am looking for help to get textlint to verify my website's relative links within my HUGO website.

Any help would be greatly appreciated!

Thanks ~

Goal

  • We have a HUGO website that supports multi-language content
  • We use a language subdirectory (example.com/en/content)
  • We want to enable textlint to verify relative links with the baseURL with the language subdirectory. (Specifically English's /en/)

Problem

  • We have included the language tag in the baseURI, but it seems to be ignored.
    • Our settings: "baseURI": "https://example.com/en/",
    • textlint acts as if our baseURI is only https://example.com/.
  • Incorrect links are being tested and returned as 404 dead links.
    • Instead of https://example.com/en/blog1, it tests https://example.com/blog1 and returns 404.

Our configurations in .textlintrc

{
  "rules": {
    "prh": {
      "rulePaths": ["../../rules/global/prh.yml"]
    },
    "@textlint-rule/require-header-id": true,
    "@textlint-rule/no-invalid-control-character": true,
    "no-dead-link": {
      "checkRelative": true,
      "baseURI": "https://example.com/en/",
      "checkRelative": false,
      "baseURI": null,
      "ignore": [
        "https://example.com/**",
        "https://api.example.com/**",
        "https://www.linkedin.com/**",
        "https://github.com/**"
      ],
      "preferGET": [],
      "ignoreRedirects": true,
      "retry": 3,
      "userAgent": "textlint-rule-no-dead-link/1.0",
      "maxRetryTime": 10
    }
  },
  "filters": {
    "allowlist": {
      "allow": [
        "product: example"
      ],
      "allowlistConfigPaths": [
        "../../rules/allow.yml"
      ]
    },
    "comments": true
  }
}

Related Issue

Relative links and i18n · Issue #146

@azu
Copy link
Member

azu commented Oct 24, 2022

baseURI + path is joined by url.resolve(from, to)

uri = URL.resolve(base, uri);

Probably, your path is written as /blog1.
As a result, url.resolve("https://example.com/en/", "/blog1") to be 'https://example.com/blog1'.

> url.resolve("https://example.com/en/", "/blog1")
'https://example.com/blog1'
> url.resolve("https://example.com/en/", "blog1")
'https://example.com/en/blog1'

We need to found suitable option/behavior for #146

📝 Some options:

  • use url-join instead of url.resolve
  • introduce another option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants