Skip to content

Add support for two features: Obsidian Wiki Links with anchors, and handling files in subdirectories during link generation#20

Open
Zhaosn wants to merge 4 commits intoCyrusky:mainfrom
Zhaosn:anchor-subdir-jump
Open

Add support for two features: Obsidian Wiki Links with anchors, and handling files in subdirectories during link generation#20
Zhaosn wants to merge 4 commits intoCyrusky:mainfrom
Zhaosn:anchor-subdir-jump

Conversation

@Zhaosn
Copy link

@Zhaosn Zhaosn commented Jan 12, 2026

New Features

Enhanced Obsidian Wiki Link Support:

  • Convert Obsidian wiki links with anchors ([[title#subtitle]]) to static web links with anchors
  • Support handling files in subdirectories during link generation, ensuring correct link paths for files stored in nested folders

Testing steps

  • Replace the content of the file "(Blog Directory)\node_modules\hexo-backlink\index.js" with the changed content of the corresponding index.ts file
  • Create test posts with both regular and anchor wiki links
  • Run hexo clean && hexo generate
  • Run hexo s -s
  • Inspect generated HTML for correct link formats
  • Test navigation to regular wiki links to confirm they work as expected
  • Test navigation to anchor wiki links (e.g., [[../Adir/a#title]] in b.md) to verify anchor jumping is accurate
  • Test navigation to cross-subdirectory links (e.g., [[../Bdir/b]] in a.md) to ensure subdirectory path resolution is correct
  • If all links work perfectly? Voila🎉! Time to celebrate your link magic~

Known Issue (Requires Hexo Config Change, Unfixable via Plugin Modifications)

Zhaosn#2

bug fixed

Zhaosn#1

Note

Due to my unfamiliarity with the npm run build command (and the files generated by this command are excessively large), I directly replacing the file content instead of the standard build process.

@Zhaosn Zhaosn marked this pull request as ready for review January 12, 2026 06:36
@Zhaosn
Copy link
Author

Zhaosn commented Jan 21, 2026

It works well for me: http://blog.zhaosn.top/ESP32-examples/00.overview/ (BTW, this is my study notes on the official ESP32 ESP-IDF examples. Perhaps it's called native development or something like that.)

When generating anchor links, replace the underlines, dots and spaces with hyphens to ensure that the links can function correctly for navigation.
if (anchor) {
// For links with anchor, use direct HTML link to preserve anchor
// Replace underscores, dots and spaces with hyphens in anchor
const formattedAnchor = anchor.replace(/[_\. ]/g, '-');
Copy link
Author

@Zhaosn Zhaosn Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to /[_\.\\\/ ]/g to support "\" or "/"

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

Successfully merging this pull request may close these issues.

1 participant