textlint-rule / textlint-rule-no-dead-link

textlint rule to check if all links are alive.
29 stars 11 forks source link

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

Open ahandsel opened 2 years ago

ahandsel commented 2 years ago

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

Problem

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 commented 2 years ago

baseURI + path is joined by url.resolve(from, to) https://github.com/textlint-rule/textlint-rule-no-dead-link/blob/e1e0cdd183b6d216c1eeeec005b19e053a192adc/src/no-dead-link.js#L272

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: