Repository: hexojs/hexo

Issue #2451: [BUG] page.post template variable behaves differently when using `hexo serve` and `hexo generate`
Created: 2017-03-14T05:11:12Z
BUG Description
I'm using page.post variable when rendering pages to support multi-language.
When using hexo serve command, the variable works as expected and gives the page's absolute path.
However when using hexo generate command (or hexo deploy), when rendering blog posts, the page.post variable gives index.html, which is unexpected.
Bug Detail
I've create a repo to isolate and test this bug. I make the page.post variable display as header of the post, and it seems that when using hexo generate, the post.path and path stays the same between pages. When I create a test/hi.md static page, all other pages has path=test/hi.html.
Way to reproduce bug
See above.
Environment Info
Node version(node -v)
v6.9.5

Hexo version
3.2.2

Your site _config.yml (I use a self-modified version of theme chan
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Project Gearbox
subtitle:
description:
author:
language:
- zh-cn
- en
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.project-gearbox.net
root: /
permalink: /:lang/:year/:title/
permalink_defaults:
  lang: zh-CN

# 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:

# Writing
new_post_name: :lang/:title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: Chan

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: git@github.com:LambdaInnovation/gearbox-blog-deploy.git
  branch: master

Your theme _config.yml
# chan theme configuration

# site setting
rss: /atom.xml
favicon: /favicon.png

# style setting
monochrome: false

# view setting
avatar: /img/GB-icon.png
avatarLink: /
maxContentWidth: 1000px # set the main content column's max-width property. keep it blank to unlimited the width
copyright: # the copyright text in the footer, could be richtext

# sidebar navigator structure
# It's a list with item that is also list.
# The item of first level list means a group of links,
# and the item of the second level list means exactly a link.
# A link item is an object whit two properties: 'name' for displaying and 'link' for redirecting.
# A link starts with http/https would be rendered as a tag with 'target="_blank"' .
# There are also some special link items representing in string: 'categories', 'tags' and 'archives'
nav:
  -
    - homepage

  -
    - blog # display a collapsible category list
    # - tags       # display a collapsible tag list

  -
    -
      name: media
      path: media/index.html

  -
    -
      name: about
      path: about/index.html

# duoshuo shortname
# refer to http://duoshuo.com
# If you use disqus then you should set disqus_shortname in your site config and disable duoshuo here.
# You also need to set 'comments' to true in the front-matter
#duoshuo: sprabbit

# jiathis share id
# refer to http://jiathis.com
#jiathis: 1589291

# open graph
twitter:
google_plus:
fb_admins:
fb_app_id:

# analytics ids
google_analytics:
baidu_statistics:

# default creative commons
# There are 6 kinds of combination and place 'none' to disable.
# - by
# - by-sa
# - by-nd
# - by-nc
# - by-nc-sa
# - by-nc-nd
# - none
# This setting could be overwritten in the front matter of a post.
# More details in https://creativecommons.org
cc: none

# FancyBox / PhotoSwipe
# Although it is called fancybox, we use PhotoSwipe instead.
# Check http://photoswipe.com
fancybox: true    # enable fancybox/photoswipe rendering
# photoswipe: true  # the same


Plugin version(npm ls --depth 0)
I've customized hexo-generator-category to change the path it generates.
hexo-site@0.0.0 D:\dev\Project\Gearbox\Blog\Source
+-- hexo@3.2.2
+-- hexo-deployer-git@0.2.0
+-- hexo-generator-archive@0.1.4
+-- hexo-generator-category@0.1.3
+-- hexo-generator-index@0.2.0 extraneous
+-- hexo-generator-tag@0.2.0
+-- hexo-renderer-ejs@0.2.0
+-- hexo-renderer-marked@0.2.11
+-- hexo-renderer-stylus@0.3.1
`-- hexo-server@0.2.0

Duplicate issue #3171: Hexo server or hexo generate two kinds of results are not the same
Created: 2018-05-28T11:33:12Z
The two running results of hexo server or hexo generate are different. Hexo server can get the custom variables in the page. Hexo g can not get the custom variables in the page..

Closing comment (2019-02-21T15:43:50Z): Possibility duplicate #2451