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

future: false not generating properly categories and tag pages #5642

Open
5 tasks done
azimonti opened this issue Mar 18, 2025 · 1 comment
Open
5 tasks done

future: false not generating properly categories and tag pages #5642

azimonti opened this issue Mar 18, 2025 · 1 comment

Comments

@azimonti
Copy link

Check List

  • I have already read Docs page & Troubleshooting page.
  • I have already searched existing issues and they are not help to me.
  • I examined error or warning messages and it's difficult to solve.
  • I am using the latest version of Hexo. (run hexo version to check)
  • My Node.js is matched the required version.

Expected behavior

I create a post for a future date in the past a few weeks ago

future: false

title: "test post"
date: 2025-03-16 12:37:00
categories:
  - [web]
tags:
  - css
  - javascript

now after the date is passed I run npx hexo generate

npx hexo generate
INFO  Config based on 2 files
INFO  Validating config
INFO  Start processing
INFO  Files loaded in 428 ms
INFO  Generated: archives/page/1/index.html
INFO  Generated: index.html
INFO  Generated: /test-post/index.html

it is generating the post but not the categories nor the tags. If then I change something so that the hash is different and I re-run then

npx hexo generate
INFO  Config based on 2 files
INFO  Validating config
INFO  Start processing
INFO  Files loaded in 412 ms
INFO  Generated: categories/index.html
INFO  Generated: archives/page/1/index.html
INFO  Generated: /test-post/index.html
INFO  Generated: tags/index.html
INFO  Generated: index.html
INFO  Generated: tags/css/page/1/index.html
INFO  Generated: categories/web/page/1/index.html
INFO  Generated: tags/javascript/page/1/index.html

I need to modify the hash after the post date is passed to have tags and categories generated

Actual behavior

The first time I run npx hexo generate for a post created in the past tags and categories are not generated.

How to reproduce?

1.future: false
2. create a post with a future date
3. after the date is passed run npx hexo generate categoties and tags are not created
4. modify something in the post
5. run npx hexo generate categoties and tags are created

Is the problem still there under Safe mode?

yes

Your Node.js & npm version

v23.10.0
10.9.2

Your Hexo and Plugin version

[email protected] /Users/marco/z_not_sync/coding/personal_site_contents/hexo_blog
├── [email protected]
├── [email protected]
├── [email protected] (git+ssh://[email protected]/azimonti/hexo-generator-archive.git#df18260567f13a45e5264f16e3bbe502f14e1dad)
├── [email protected] (git+ssh://[email protected]/azimonti/hexo-generator-category.git#2795a83b0d82b5f3108a1c36c0eada0ba1f8fe59)
├── [email protected]
├── [email protected] (git+ssh://[email protected]/azimonti/hexo-generator-tag.git#8e7640ad78ef38c78b9aef175b3d0d33905ded3f)
├── [email protected] (git+ssh://[email protected]/azimonti/hexo-pagination.git#0c8dfcc58bc2f8e7e4ba75105d5b56d25bd2bf76)
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Your package.json

{
  "name": "hexo-site",
  "version": "1.0.0",
  "private": true,
  "hexo": {
    "version": "7.3.0"
  },
  "dependencies": {
    "cheerio": "^1.0.0-rc.12",
    "hexo": "^7.3.0",
    "hexo-fs": "^5.0.0",
    "hexo-generator-archive": "github:azimonti/hexo-generator-archive#explicit-paging",
    "hexo-generator-category": "github:azimonti/hexo-generator-category#explicit-paging",
    "hexo-generator-index": "^4.0.0",
    "hexo-generator-tag": "github:azimonti/hexo-generator-tag#explicit-paging",
    "hexo-pagination": "github:azimonti/hexo-pagination#overwrite-latest",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-marked": "^7.0.0",
    "hexo-renderer-stylus": "^3.0.0",
    "hexo-server": "^3.0.0",
    "hexo-util": "^3.3.0",
    "moment-timezone": "^0.5.45"
  }
}

Your site's _config.yml (Optional)

title: My blog
root: /blog/
permalink: ':year/:month/:day/:title/'
permalink_defaults: null
pretty_urls:
  trailing_index: false
  trailing_html: true
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: ':lang'
skip_render:
  - /assets/**/*
  - /dev/**/*
  - /files/**/*
  - /img/**/*
new_post_name: ':title.md'
default_layout: post
titlecase: false
external_link:
  enable: true
  field: site
  exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: false
syntax_highlighter: null
highlight:
  enable: true
  line_number: false
  auto_detect: true
  tab_replace: ''
prismjs:
  enable: false
index_generator:
  single_post: false
  path: ''
  per_page: 0
  max_posts: 15
  order_by: '-date'
per_page: 12
pagination_dir: page
inverse_pagination: true
default_category: uncategorized
category_map: null
tag_map: null
archive_generator:
  yearly: true
  monthly: true
  daily: false
  order_by: date
  explicit_paging: true
  rename_last: true
category_generator:
  order_by: date
  explicit_paging: true
  rename_last: true
tag_generator:
  order_by: date
  explicit_paging: true
  rename_last: true
meta_generator: false
date_format: YYYY-MM-DD
time_format: HH:mm:ss
updated_option: mtime
include: null
exclude: null
ignore: null
theme: quantum_quest
deploy:
  type: ''
feed:
  rss: true
  atom: true
  post_limit: 20
sidebar:
  categories_limit: 7
  tags_limit: 7
  recent_posts_limit: 7
  archive_posts_limit: 7
post_calendar:
  excerpt_character_limit: 0
  contents_character_limit: 140

Others

No response

@azimonti
Copy link
Author

I did some investigation, and I noticed that even future post are all added to db.json (is this expected?). checking the code, for future posts categories and tags are reset to ([]), and when the date is getting in the past, the file is never regenerated (so tags and categories are empty).

I try to make a fix external (could not find a way to patch the code) and created a script which is setting for all future post in db.json the hash and the modified to 0.

BASHSCRIPTDIR=$(cd "$(dirname "$0")" || exit ; pwd)
ROOTDIR=$( dirname "${BASHSCRIPTDIR}")
BLOGPOSTDIR="${ROOTDIR}/source/_posts"
DBJSONFILE="${ROOTDIR}/db/prod/db.json"

FILES=()
while IFS= read -r FILE; do
  FILES+=("$FILE")
done < <(find "${BLOGPOSTDIR}" -type f -name "*.md")

CURRENT_DATETIME=$(date '+%Y-%m-%d %H:%M:%S')
TO_MODIFY=()

for FILE in "${FILES[@]}"; do
  POST_DATETIME=$(awk '/^date:/ {print $2, $3; exit}' "$FILE")
  if [[ "$POST_DATETIME" > "$CURRENT_DATETIME" ]]; then
    STRIPFILE="${FILE#"$ROOTDIR"/}"
    TO_MODIFY+=("$STRIPFILE")
  fi
done

if [[ ${#TO_MODIFY[@]} -gt 0 ]]; then
  node "${ROOTDIR}/bash_scripts/node_fix_db_hash.js" "$DBJSONFILE" "${TO_MODIFY[@]}"
fi
'use strict';
const fs = require('fs');

const dbFile = process.argv[2];
const filesToModify = new Set(process.argv.slice(3));
const dbData = JSON.parse(fs.readFileSync(dbFile, 'utf8'));

dbData.models.Cache.forEach(entry => {
  if (filesToModify.has(entry._id)) {
    entry.hash = "0000000000000000000000000000000000000000";
    entry.modified = 0;
  }
});

fs.writeFileSync(dbFile, JSON.stringify(dbData));

In this way, when the date is passed, the post is considered updated and it correctly generates it with tags and categories.

I would see as options to fix this bug either:

  1. do not add future posts to db.json
  2. set hash and modified to 0 after the generate process in db.json for future posts, so when the date is passed the post is considered updated and it is regenerated with tags and categories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant