hexo-front-matter is a JavaScript library dedicated to parsing and stringifying front-matter data, supporting both YAML and JSON formats. It is a fundamental component within the Hexo static site generator ecosystem but is designed for standalone use for general front-matter processing needs. The current stable version is 5.0.0, published approximately 5 months ago. The package maintains an active development cycle, with major versions frequently released to align with Node.js LTS updates, or to introduce significant internal refactors and bug fixes, such as the critical change to timezone handling introduced in v5.0.0. Key differentiators include its versatile support for both YAML and JSON front-matter, flexible options for prefixing separators, and a clear API for parsing, stringifying, splitting, and escaping front-matter sections, making it a robust solution for various content management or static site generation workflows.
npm install hexo-front-matterVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse both YAML and JSON front-matter from a string and how to stringify an object back into a front-matter formatted string.
Review the official documentation on timezone behavior for v5.x and adjust your `defaultTimeZone` configuration or date handling logic if necessary. Ensure timestamps either include timezone information or are handled consistently with the new default behavior.
Avoid `hexo-front-matter@4.2.0` and upgrade directly to `hexo-front-matter@4.2.1` or newer to ensure correct TypeScript type definitions are available.
Upgrade your Node.js environment to version 14.x or newer to ensure compatibility.
Ensure your Node.js environment is version 12.x or higher, but less than 14.x, if you need to remain on a 3.x release. For current usage, upgrade to Node.js 14+ and `hexo-front-matter@4.0.0+`.
Update your CommonJS `require` statements from `const yfm = require('hexo-front-matter');` to `const { parse: yfm } = require('hexo-front-matter');` or `const { parse, stringify } = require('hexo-front-matter');`.Adjust the CommonJS import to destructure the `parse` function: `const { parse } = require('hexo-front-matter'); parse(str);` or `const yfm = require('hexo-front-matter').parse; yfm(str);`Review your date formats in front-matter and ensure they include explicit timezone information (e.g., `2023-10-27T10:00:00Z`). Alternatively, configure the `defaultTimeZone` option when calling `parse()` to match your expected behavior.
Upgrade your Node.js environment to version 14.15.0 or higher. The package specifies `>=20.19.0` for v5.0.0, so updating to the latest LTS Node.js is recommended.