2.0.28 • Published 2 days ago

@sphido/hashtags v2.0.28

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@sphido/hashtags

Search Markdown for hashtags and replaces them with a links [#hashtag](/tag/hashtag) code.

Install

yarn add @sphido/hashtags

API

getHashtags(content)

Function getHashtags() searches the string for all hashtags and returns them as an array. The input content parameter is expected in Markdown format, function automatically skips preformatted text in Markdown syntax.

import {getHashtags} from '@sphido/hashtags';

const tags = getHashtags('#one #two #three `color: #red`');
console.log(tags); // will be ['#one', '#two', '#three']; 

tagsToMarkdown(content, tags = [], options?)

Function tagsToMarkdown() expect at last two parameters on the input - content and tags Replace hashtags with Markdown syntax for links [#hash](/tag/hash)

import {getPages, allPages, readFile} from '@sphido/core';
import {getHashtags, tagsToMarkdown} from '@sphido/hashtags';

const pages = await getPages({path: 'content'});

for (const page of allPages(pages)) {
	page.content = await readFile(page.path);
	page.tags = getHashtags(page.content);

	// 
	page.content = tagsToMarkdown(page.content, page.tags);
}

hashtags(page, dirent)

Function hashtags() search for all hashtags in page.content. In case that page.content property is empty, function will load file content automatically. All found tags are then stored in a page.tags property as an array. Function will also automatically replace hashtags to Markdown syntax for links [#hash](/tag/hash).

import {getPages, allPages} from '@sphido/core';
import {hashtags} from '@sphido/hashtags';

const pages = await getPages({path: 'content'}, hashtags);

for (const page of allPages(pages)) {
	console.log(page.tags, page.content);
}

Source codes

@sphido/hashtags

2.0.28

2 days ago

2.0.26

2 days ago

2.0.25

2 months ago

2.0.24

3 months ago

2.0.22

4 months ago

2.0.23

4 months ago

2.0.20

7 months ago

2.0.21

6 months ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago