项目作者: tg44

项目描述 :
Automatically cross-links pages at first appearance
高级语言: JavaScript
项目地址: git://github.com/tg44/vuepress-plugin-auto-crosslinker.git
创建时间: 2021-06-05T17:09:42Z
项目社区:https://github.com/tg44/vuepress-plugin-auto-crosslinker

开源协议:

下载


Vuepress Plugin auto-crosslinker

npm

This is a vuepress plugin wrapper around markdown-it-auto-crosslinker!

Installation

  1. npm i vuepress-plugin-auto-crosslinker -D

Usage

  1. plugins: {
  2. 'auto-crosslinker': { /* options */ }
  3. },

Note that Vuepress allows multiple syntaxes to register plugins. See Vuepress documentation on how to use a plugin for more information.

What it does?

Wiki like pages, usually cross-links to each other.
A good (wiki) page only links to another page at the first occurrence.
So if you have a wiki about fruits, when you mention apple in a page at first time,
you want to link it to the corresponding page, but any more mentions should not appear as a link.

We can create a dictionary about where we want to link, and for what appearances we want to change links.

The plugin will get the links one-by-one, and change the first keyword in a document to a link. For every document.

No more missing links, everything is automatically cross-linked to each other!

Options

dictionary

Default: {}

An object where the key is the link, and the value is a key-word list.

  1. const dictionary = {
  2. '/apple.md': ['apple', 'apples'],
  3. '/pear.md': ['pear', 'pears'],
  4. '/fruit.md': ['fruit', 'fruits'],
  5. }

wholeWords

Default: true

Match to whole words.

  1. const dictionary = {'/berry.md': ['berry']}
  2. md
  3. .use(crosslinker, {dictionary, wholeWords: true})
  4. .render('Test raspberry is a berry?')
  5. //the same as
  6. md
  7. .render('Test raspberry is a [berry](/berry.md)?')
  8. md
  9. .use(crosslinker, {dictionary, wholeWords: false})
  10. .render('Test raspberry is a berry?')
  11. //the same as
  12. md
  13. .render('Test rasp[berry](/berry.md) is a berry?')