hexojs / hexo

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

url_for function got the error url #3214

Closed 9monsters closed 6 years ago

9monsters commented 6 years ago

Environment Info

Node version(node -v): v10.7.0

Your site _config.yml (Optional):

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://w.wzzx.xyz
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

Your theme _config.yml (Optional): next theme config snippet

menu:
  home: / || home
  about: /about || user
  tags: /tags || tags
  categories: /categories || th
  archives: /archives || archive
  schedule: /schedule || calendar
  sitemap: /sitemap.xml || sitemap
  # commonweal: /404/ || heartbeat

# Enable/Disable menu icons / item badges.
menu_settings:
  icons: true
  badges: true

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

$ npm ls --depth 0
hexo-site@0.0.0 /Users/me/Documents/myblog
├── gulp@3.9.1
├── gulp-htmlclean@2.7.22
├── gulp-htmlmin@4.0.0
├── gulp-minify-css@1.2.4
├── gulp-uglify@3.0.0
├── hexo@3.7.1
├── hexo-blog-encrypt@2.0.8
├── hexo-deployer-git@0.3.1
├── hexo-filter-flowchart@1.0.4
├── hexo-filter-plantuml@1.0.2
├── hexo-filter-sequence@1.0.3
├── hexo-generator-archive@0.1.5
├── hexo-generator-category@0.1.3
├── hexo-generator-feed@1.2.2
├── hexo-generator-index@0.2.1
├── hexo-generator-searchdb@1.0.8
├── hexo-generator-seo-friendly-sitemap@0.0.21
├── hexo-generator-sitemap@1.2.0
├── hexo-generator-tag@0.2.0
├── hexo-pdf@1.1.1
├── hexo-related-popular-posts@3.0.1
├── hexo-renderer-ejs@0.3.1
├── hexo-renderer-marked@0.3.2
├── hexo-renderer-stylus@0.3.3
├── hexo-server@0.2.2
├── hexo-symbols-count-time@0.4.4
├── hexo-tag-aplayer@3.0.4
├── hexo-tag-bilibili@0.2.1
├── hexo-tag-cloud@2.0.11
├── hexo-tag-dplayer@0.3.3
├── hexo-tag-plantuml@1.0.0
└── hexo-wordcount@3.0.2

npm ERR! peer dep missing: webpack@^4.4.0, required by mini-css-extract-plugin@0.4.0
npm ERR! peer dep missing: webpack@^4.x.x, required by webpack-cli@3.0.4

For BUG

{% macro render(name, value) %}
{% import 'menu-badge.swig' as menu_badge %}

  {% set itemURL = value.split('||')[0] | replace('//', '/', 'g') | trim %}
  <li class="menu-item menu-item-{{ itemName | replace(' ', '-', 'g') }}{{ item_active(itemURL, 'menu-item-active') }}">
    <a href="{{ url_for(itemURL) }}" rel="section">
    {%- if theme.menu_settings.icons %}
      <i class="menu-item-icon fa fa-fw fa-{{ value.split('||')[1] | trim | default('question-circle') }}"></i> <br />{#
  #}{% endif %}

    {{- __('menu.' + name ) | replace('menu.', '') -}}

    {%- if theme.menu_settings.badges -%}
      {{- menu_badge.render(name) | trim -}}
    {%- endif -%}

    </a>
  </li>

{% endmacro %}

when use url_for funtion, hexo render the error relative url, eg. http://localhost:4000/2016/10/08/Spring-Boot%E4%BD%BF%E7%94%A8RabbitMQ/ then hexo render the tags url as http://localhost:4000/2016/10/08/Spring-Boot%E4%BD%BF%E7%94%A8RabbitMQ/tags but what I want is http://localhost:4000/tags

9monsters commented 6 years ago

sorry, using url_for error