4

In source/_posts I have post.md and post/ directory to hold assets for post.md.

In post/ I have js/main.min.js which is being used in post.md to illustrate something.

Hexo is picking up the main.min.js and creating a post for it. How can I get around this?

justin
  • 3,357
  • 1
  • 23
  • 28

3 Answers3

4

The only solution I have found was to include a directory for the post under source i.e. source/post (outside / alongside source/_posts).

You can then put your assets there and refer to them in md file e.g.

<script src="/post/js/main.min.js"></script>

Btw, I have tried using _config.yml's skip_render:

skip_render:
  - "**/*.js"
  - "*/*.js"
  - "_posts/post/js/main.min.js"

and other variations but they all result in main.min.js being rendered as a post.

justin
  • 3,357
  • 1
  • 23
  • 28
  • 1
    I have tried the `skip_render` for skip js files,it should work after you made a clean by `hexo clean` – fatfatson Jul 04 '18 at 01:59
4

I had a similar issue, but it was with json files. In my case all json files would be turned into pages and I didn't want any of them to be. So what I ended up doing was creating a file extend.js and placing it inside of the scripts folder in my theme. Then I included this bit of code.

hexo.extend.filter.register('after_init', function () {
  // Remove json files being inserted to db.json -> Pages

  var listSync = hexo.extend.renderer.list(true),
      listAsync = hexo.extend.renderer.list();

  delete listSync.json;
  delete listAsync.json;
});

The possible objects you can delete are, htm, html, css, js, json, swig, yml, yaml. Hope that helps.

cnotethegr8
  • 7,342
  • 8
  • 68
  • 104
  • Thanks! I haven't tried it but will definitely have a look if I run into similar problems later on. – justin Feb 13 '16 at 14:31
2

I think Hexo will ignore any file that has an underscore, so you need to rename your .js file to _main.min.js

GWed
  • 15,167
  • 5
  • 62
  • 99
  • True, I've tried this and Hexo did not generate the post. I was not, however, able to link to the js file in my .md. Maybe I haven't played enough with it and hit the right URL for it. It's working the way it's set up, outside _posts/, so I'm inclined to keep it that way. Thanks for the tip though! – justin Nov 15 '15 at 21:31
  • silly suggestion, but you also need to renamed the file with the underscore where you reference it in your .md file. Assume you did that? Easiest way to check the URL is look in public folder and see if your js file is in there – GWed Nov 16 '15 at 11:53
  • lol np. Yes I had changed the link. I had forgotten about `hexo generate` to see the public directory (was just serving from `hexo server` - it's been a while). Latter does not generate public. In any case, when js filename is underscore prefixed, it is not copied over in public directory and so there is no way to link to it (nor is an .html file generated for it - the original issue). No wonder I was not able to guess the URL. .png and .svg files copied fine though. – justin Nov 17 '15 at 22:08