hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.62k stars 4.87k forks source link

helper function <%- css(path, ...) %> not working fine with relative_url #4895

Closed bill-xia closed 1 year ago

bill-xia commented 2 years ago

Check List

Please check followings before submitting a new issue.

Expected behavior

relative_url: true is configured in _config.yml.

<%- css('/css/style.css') %> in public/archives/page/2/index.html should generate:

<link rel="stylesheet" href="../../../css/style.css">

Actual behavior

It actually generates:

<link rel="stylesheet" href="../../../../css/style.css">

Sometimes (in another theme) it only generates one ../, I think it may be a cache problem. I'm not sure it's not a problem outside hexo.

How to reproduce?

relative_link: true

* `hexo g`
* catch `public/archives/page/02/index.html`

The `<link>` tag of `/css/style.css` can be with a wrong relative path.

## Is the problem still there under "Safe mode"?

Under safe mode, these pages cannot be generated, so I can't be sure.

<!--
https://hexo.io/docs/commands#Safe-mode

"Safe mode" will disable all the plugins and scripts.
If your problem disappear under "Safe mode" means the problem is probably at your newly installed plugins, not at hexo.
-->

## Environment & Settings

**Node.js & npm version(`node -v && npm -v`)**

<!--
Please paste the output between two "```" provided below
-->

v16.13.1 8.3.2


**Your site `_config.yml`** (Optional)

<!--
Please paste the content of your _config.yml between two "```" provided below
-->

```yaml

Your theme _config.yml (Optional)

Hexo and Plugin version(npm ls --depth 0)

hexo-site@0.0.0 /Users/wilson/Developer/proj/hexo-theme
├── hexo-deployer-git@3.0.0
├── hexo-generator-archive@1.0.0
├── hexo-generator-category@1.0.0
├── hexo-generator-feed@3.0.0
├── hexo-generator-index@2.0.0
├── hexo-generator-sitemap@2.2.0
├── hexo-generator-tag@1.0.0
├── hexo-renderer-ejs@1.0.0
├── hexo-renderer-markdown-them@1.0.1
├── hexo-renderer-stylus@2.0.1
├── hexo-server@2.0.0
├── hexo-theme-landscape@0.0.3
├── hexo@6.0.0
├── katex@0.13.24
└── markdown-them@1.0.15

Your package.json package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "6.0.0"
  },
  "dependencies": {
    "hexo": "^6.0.0",
    "hexo-deployer-git": "^3.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-index": "^2.0.0",
    "hexo-generator-sitemap": "^2.1.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-markdown-them": "^1.0.1",
    "hexo-renderer-stylus": "^2.0.0",
    "hexo-server": "^2.0.0",
    "hexo-theme-landscape": "^0.0.3",
    "katex": "^0.13.18",
    "markdown-them": "^1.0.13"
  }
}

Others

stevenjoezhang commented 1 year ago

Relevant PR: https://github.com/hexojs/hexo/pull/4789

stevenjoezhang commented 1 year ago

Fixed in https://github.com/hexojs/hexo/pull/5217