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

Won't generate with post_asset_folder on and permalink ending with ".html" #2134

Closed
mogita opened this issue Sep 3, 2016 · 10 comments · Fixed by #5153
Closed

Won't generate with post_asset_folder on and permalink ending with ".html" #2134

mogita opened this issue Sep 3, 2016 · 10 comments · Fixed by #5153
Labels
bug Something isn't working

Comments

@mogita
Copy link

mogita commented Sep 3, 2016

Environment Info

Node version(node -v)

v6.5.0

Your site _config.yml

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: 御宅型
subtitle: mogita 的技术博客
description: mogita 的技术博客
author: mogita
language: zh-CN
timezone: Asia/Shanghai

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://otaku.mogita.com
root: /
permalink: :year/:month/:title.html
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:

# Writing
new_post_name: :year-:month-:day-:title.md
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: true
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: clean-blog

#### Analytics
cnzz: true

feed:
  type: atom
  path: atom.xml
  limit: 20
  hub:

Your theme _config.yml

# Header
menu:
  关于: /about

# Title on top left of menu. Leave empty to use main blog title
menu_title: 

# URL of the Home page image
index_cover: /img/header.jpg

# Default post title
default_post_title: Untitled

# Comments. Choose one by filling up the information
comments:
  # Disqus comments
  disqus_shortname: otaku-mogita

# Google Analytics Tracking ID
google_analytics:

# Addthis ID
addthis:

# Social Accounts
twitter_url: https://twitter.com/mogita
twitter_handle:
facebook_url:
github_url: https://github.com/mogita
gitlab_url:
linkedin_url:
mailto:

Plugin version(npm ls --depth 0)

hexo-site@0.0.0 /Users/mogita/Documents/Dev/otaku_blog
├── hexo@3.2.2
├── hexo-deployer-ftpsync@0.1.1
├── hexo-generator-archive@0.1.4
├── hexo-generator-category@0.1.3
├── hexo-generator-feed@1.2.0
├── hexo-generator-index@0.2.0
├── 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

For BUG

  • Generation always fails with a fatal error ENOTDIR
  • To reproduce this, set post_asset_folder: true and permalink: :year/:month/:title.html in Hexo's _config.yml. Then hexo new a-new-post, put an image into the folder a-new-post created by hexo's new command. To change or not the a-new-post.md file is not essential. Now hexo generate and the error should emerge.

Thank you for reading thru, looking forward to a solution.

@leokongwq
Copy link

I am met this problem too, did you find the way to resolve this ?

@leokongwq
Copy link

leokongwq commented Oct 13, 2016

@mogita I am already solved this problem; I midified the file post_asset.js in path hexo/lib/models/post_asset.js; my code is:

  PostAsset.virtual('path').get(function() {
    var Post = ctx.model('Post');
    var post = Post.findById(this.post);
    if (!post) return;
    // PostAsset.path is file path relative to `public_dir`
    // no need to urlescape, #1562
      //如果生成的文章路径是以html结尾的, 如:  2016/10/13/byte-order.html,
      // 则对应的资源路径应该是: 2016/10/13/byte-order + this.slug
      var reg = new RegExp("html" + "$");
      if(reg.test(post.path)) {
          var assetPath = post.path.substr(0, post.path.lastIndexOf("."));
          return pathFn.join(assetPath, this.slug);
      }
      return pathFn.join(post.path, this.slug);
  });

you can try it!

@mogita
Copy link
Author

mogita commented Oct 15, 2016

Hi @leokongwq

Thanks for the solution. I haven't tried your code yet, but I assume it will only process the slugs ending with "html", am I right? What if the permalink ends with, say, ".eva"? (This one was used on my wordpress blog in the past years :D)

@Alex1990
Copy link

If the permalink is set to :title.html, then a file named :title.html will be generated in public directory. Then, the path of the post assert is :title.html/post_asset_relative_path, so, it needs a directory named :title.html, but the file with same name is exist. In brief, the path of the post assert should not be prefixed with the post path.

@Alex1990
Copy link

Alex1990 commented Dec 14, 2016

Maybe, the pathFn.join('_' + post.path, this.slug); is better.

@idleworx
Copy link

This needs a fix, running into the same issue.
Even if you only use permalink: :year/:month/:title.html in the config file, the blog posts are all /year/month/title/ not /year/month/title.html

This is helpful for being able to migrate from other blogging platforms like blogger.

@Alex1990
Copy link

Alex1990 commented May 4, 2017

Today, I find if the path segment is begin with _, a 404 error will happen on the github pages. So the below code will be better:

File: lib/models/post_asset.js:

var postPath = post.path;
if (/\.html$/.test(postPath)) {
  postPath = postPath.slice(0, postPath.lastIndexOf('.'));
}
return pathFn.join(postPath, this.slug);

@NoahDragon
Copy link
Member

@Alex1990 Could you please create a PR for it?

@Alex1990
Copy link

Alex1990 commented May 4, 2017

@NoahDragon Yes. But I don't understand how to implement a test for it. How to mock the post.path?

@NoahDragon
Copy link
Member

@Alex1990 Thanks. Hmmm... I see the problem. I'm also not familiar with that part. I will take a look.

@stale stale bot added the wontfix This will not be worked on label Sep 27, 2017
@NoahDragon NoahDragon added need-verify and removed wontfix This will not be worked on labels Sep 27, 2017
@hexojs hexojs deleted a comment from stale bot Sep 27, 2017
JLHwung added a commit that referenced this issue Dec 4, 2017
@JLHwung JLHwung added bug Something isn't working and removed need-verify labels Dec 4, 2017
JLHwung added a commit that referenced this issue Dec 4, 2017
JLHwung added a commit that referenced this issue Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants