hexo-recover: rebuild the Markdown sources from a generated Hexo site, then verify the rebuild #5825
Belyenochi
started this conversation in
Show and tell
Replies: 1 comment
|
Update — v0.2.0 adds presets for eight more themes, with auto-detection. Butterfly, Fluid, Icarus, Volantis, Stellar, Keep, Redefine and Landscape now work out of the box next to NexT; How they were added, since it may be useful to others working with generated Hexo sites: I built one small site per theme with Hexo 8 and the theme's current release, and read the selectors from the real output. Those sites are in the repo as fixtures, and the tests recover each one, compare the posts to the source Markdown, and run Two things I did not expect:
Still looking for samples of themes not on the list: one post page plus the index page is enough to add a preset. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sharing a small tool for a situation I ended up in: I switched machines and the Hexo
source/folder never made it across — the Markdown was gone for good, while the blog itself was still online. All I had was the generated HTML in.deploy_git, so I wrote something to turn that back into the Hexo project.hexo-recover rebuilds the Hexo project from that HTML — posts with front matter, images, and the site/theme config as far as the pages reveal it — and then lets you verify the result by rendering it back through Hexo and diffing every post body against the original.
Repo: https://github.com/Belyenochi/hexo-recover · npm: https://www.npmjs.com/package/hexo-recover
What makes it different from a generic HTML→Markdown converter is that it knows Hexo's exact output shapes: the line-numbered
figure.highlightcode tables,headerlinkanchors inside headings, headings and hard breaks inside list items, indented vs fenced code, and the CommonMark emphasis rules that currentmarkedenforces but older versions did not. Each rule is pinned by a test, and each one came from a real difference found by the verify step.Supported themes (v0.2.0, detected automatically): NexT, Butterfly, Fluid, Icarus, Volantis, Stellar, Keep, Redefine and Landscape. Each preset was read from a site generated with the theme's current release; those sites are fixtures in the repo, and the tests recover each one, compare the posts to the source Markdown, and run
verifyagainst the NexT rendering of the same posts. Title, dates and tags come from the Open Graph tags Hexo writes into every page, so they do not depend on the theme at all; the theme-specific parts are the body container, category links, index excerpts, menu and avatar. For a theme not on the list,--body-selectorpointing at the article body is enough to get the posts back.Results on the site I recovered (25 posts, NexT 5.1.4 originally, rebuilt on Hexo 8 + NexT 8): every post identical to the original once whitespace is ignored, zero structural differences.
Current limits: the theme config written out is always NexT 8's — menu, avatar and social links read from another theme are carried over into it. Themes that show only the day of a post (Butterfly, Icarus, Landscape) get the exact UTC instant in the front matter rather than a local time. Posts are located by the
YYYY/MM/DD/slug/permalink unless you pass--post-glob.verifydoes not run Hexo for you.If your site uses a theme not listed above, a post page and the index page are all that is needed to add a preset.
All reactions