Fixing Hexo Not Generating Files

If you’re having trouble with Hexo not generating files, check for broken symbolic links in the source directory tree:

1
find ./ -type l -exec test ! -e {} \; -print

It appears that if there are broken symbolic links in the source directory tree, Hexo will not generate any new files, even if you create a new post (I haven’t tried with pages or scaffold templates). This may be by design, but I didn’t see any warnings when I went to generate so I figured I’d share my findings here.

This issue is reproducible with:

  • hexo: 5.2.0
  • hexo-cli: 3.1.0
  • os: Darwin 19.6.0 darwin x64
  • node: 12.13.1

Steps to reproduce

Start with a clean tree:

1
2
3
4
5
6
7
8
$ hexo g
INFO Validating config
INFO === Checking package dependencies ===
INFO === Checking theme configurations ===
INFO === Registering Hexo extensions ===
INFO Start processing
INFO Files loaded in 1.02 s
INFO 0 files generated in 1.23 s

No files are generated as expected.

Now create a symlink to a file. The file doesn’t have to be empty it can be any file you can symlink to and then delete. I created a file in the source/images directory like this:

1
2
3
4
5
6
$ cd source/images
$ touch testfile.png
$ ln -s testfile.png testfile-link.png
$ ls -l testfile*
lrwxr-xr-x 12 cbergeron 24 Dec 20:04 testfile-link.png -> testfile.png
.rw-r--r-- 0 cbergeron 24 Dec 20:04 testfile.png

Here we can see the new file testfile.png and the symlink pointing to it testfile-link.png.

Let’s delete the original file and leave the broken symlink:

1
$ rm testfile.png

Now we can now see that symlink is dangling (broken):

1
2
find ./ -type l -exec test ! -e {} \; -print
.//testfile-link.png

You could also use ls to see the broken symlink.

Next, create a new blog post using your favorite editor or via the command line:

1
2
3
4
5
6
$ hexo new Testing-hexo-file-gen-issue
INFO Validating config
INFO === Checking package dependencies ===
INFO === Checking theme configurations ===
INFO === Registering Hexo extensions ===
INFO Created: source/_posts/testing.md

At this point, we expect that running hexo g will result in Hexo finding the new file and rendering the new post into an html page in the public directory. However this is what happens:

1
2
3
4
5
6
7
8
$ hexo g
INFO Validating config
INFO === Checking package dependencies ===
INFO === Checking theme configurations ===
INFO === Registering Hexo extensions ===
INFO Start processing
INFO Files loaded in 1 s
INFO 0 files generated in 1.29 s

Uh oh, 0 files generated. There are a few ways you can fix the broken symlink. You can remove it or you can replace the file that it’s pointing to.

After fixing the symlink and trying to Hexo generate again:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

$ rm source/images/testfile-link.png
$ hexo g
INFO Validating config
INFO === Checking package dependencies ===
INFO === Checking theme configurations ===
INFO === Registering Hexo extensions ===
INFO Start processing
INFO Files loaded in 1.2 s
INFO Generated: sitemap.xml

... a lot of files genereated here ...

INFO Generated: content.json
INFO 169 files generated in 1.3 s

Abracadabara! Now Hexo is generating new posts as you would expect.

Author

Chris Bergeron

Posted on

12-24-2020

Updated on

12-24-2020

Licensed under

Comments