@imtk/md-links-graph
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

md-links-graph

Npm package version GitHub license

Create a graph data structure based on Markdown content and links.

Install

With yarn:

yarn add @imtk/md-links-graph

With npm:

npm add @imtk/md-links-graph

Usage

import { createGraph } from '@imtk/md-links-graph';

const posts = [
  {
    url: '/post-1',
    title: 'Post 1',
    content: 'Markdown content for post 1'
  },
  {
    url: '/post-2',
    title: 'Post 2',
    content: 'Post 2 linked to [post 1](/post-1)'
  }
];

const graph = createGraph(posts);

graph.nodes;
// [
//   {
//     url: '/post-1',
//     text: 'Post 1',
//     id: 0
//   },
//   {
//     url: '/post-2',
//     text: 'Post 2',
//     id: 1
//   }
// ]

graph.edges;
// [
//   {
//     source: '1',
//     target: '0'
//   }
// ];

Types

Node

type Url = string;

type Node = {
  id: number;
  text: string;
  url: Url;
};

Edge

type Edge = {
  source: string;
  target: string;
};

Post input

type PostMarkdown = {
  url: string;
  title: string;
  content: string;
};

License

MIT License © 2022 TK

Package Sidebar

Install

npm i @imtk/md-links-graph

Weekly Downloads

2

Version

1.3.0

License

MIT

Unpacked Size

7.01 kB

Total Files

12

Last publish

Collaborators

  • leandrotk