-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
97 lines (88 loc) · 3.12 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Root as _HastRoot } from "hast";
import { Root as _MdastRoot } from "mdast";
import { Link, ToLink, WikiLink as _WikiLink } from "remark-obsidian-link";
import { Processor } from "unified";
export namespace Metamark {
export type MdastRoot = _MdastRoot;
export type HastRoot = _HastRoot;
export type MdastLink = Link;
export type WikiLink = _WikiLink;
export namespace Obsidian {
export namespace Vault {
export interface FileData {
fileName: string;
slug: string;
firstParagraphText: string;
frontmatter: Record<string, any>;
html: string;
toc: TocItem[];
}
export interface ProcessOptions {
/**
* Given a dirpath, build a `Set<string>` of filepaths,
* representing pages that should be turned into html,
* and linked to from other pages.
*
* The default behavior is to check the file's `frontmatter`
* for `public: true`. Only if `public` exists and is set to
* `true` is the filePath added to the `FilePathAllowSet`.
*/
filePathAllowSetBuilder?: FilePathAllowSetBuilder;
/**
* This builder function constructs the unified.js processor
* that is used to both parse markdown into mdast, and transform
* markdown into html. It takes in a `toLink` function that can
* be controlled as well via `toLinkBuilderOpts`
*
* The default behavior is a collection of common markdown and
* html plugins.
*/
unifiedProcessorBuilder?: UnifiedProcessorBuilder;
/**
* These options control the `toLinkBuilder` function execution. In short,
* `remark-obsidian-link` requires a `toLink` function, and this function
* builds that function. For example,
*
* ```ts
* const toLink = toLinkBuilder(opts);
* const mdastLink = toLink(wikiLink);
* ```
*
* By default the options are:
*
* ```ts
* {
* filePathAllowSet: [override or default],
* prefix: '/content',
* toSlug: (s: string) => slugify(s, {decamelize: false}),
* }
* ```
*
* The resulting behavior is approximately as follows:
*
* ```ts
* // original string slice from markdown: "[[Wiki Link]]"
* const wikiLinkInput = { value: "Wiki Link" };
* const mdastLinkOutput = { value: "Wiki Link", uri: "content/wiki-link" }
* ```
*/
toLinkBuilderOpts?: ToLinkBuilderOpts;
}
export type FilePathAllowSetBuilder = (dirPath: string) => Set<string>;
export type UnifiedProcessorBuilder = (_: {
toLink: ToLink;
}) => Processor<MdastRoot, MdastRoot, HastRoot, HastRoot, string>;
export type ToLinkBuilderOpts = {
filePathAllowSet: Set<string>;
toSlug: (s: string) => string;
prefix: string;
};
export type ToLinkBuilder = (_: ToLinkBuilderOpts) => ToLink;
}
}
export interface TocItem {
title: string;
depth: number;
id: string;
}
}