-
Notifications
You must be signed in to change notification settings - Fork 0
/
dep.ts
105 lines (79 loc) · 2.9 KB
/
dep.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
98
99
100
101
102
103
104
105
/// native
export { ensureDir, expandGlob } from "std/fs/mod.ts";
export { format as formatDate } from "std/datetime/mod.ts";
export { extract as frontmatter } from "std/front_matter/yaml.ts";
export { join } from "std/path/mod.ts";
export { serve } from "std/http/server.ts";
/// third-party
export { Application, Context, type HandlerFunc, type MiddlewareFunc } from "https://deno.land/x/abc@v1.3.3/mod.ts";
export { Feed } from "npm:feed";
export { default as HighlightJS } from "https://unpkg.com/@highlightjs/cdn-assets@11.6.0/es/highlight.min.js";
export { html, tokens } from "https://deno.land/x/rusty_markdown@v0.4.1/mod.ts";
export { useDartSass } from "https://raw.githubusercontent.com/MarkTiedemann/deno-dart-sass/0.3.0/mod.ts";
export { Yandlebars } from "https://raw.githubusercontent.com/cybertim/yandlebars/main/mod.ts";
/// project
export const baseDirectory = Deno.cwd();
export interface LooseObject {
[key: string]: any;
}
export interface PostMetadata {
date: string
file: string
slug: string
tags: string
title: string
tldr: string
}
export function merge(source: any, target: any) {
for (const [key, val] of Object.entries(source)) {
if (val !== null && typeof val === "object") {
if (target[key] === undefined) {
target[key] = new val.__proto__.constructor();
}
merge(val, target[key]);
} else {
target[key] = val;
}
}
return target;
/// via https://gist.github.com/ahtcx/0cd94e62691f539160b32ecda18af3d6?permalink_comment_id=3889214
}
export const order = (maybeObject?: any) => {
// TODO
// : fix issue with dates becoming empty object
// : create Deno port
if (!maybeObject)
return null;
if (maybeObject instanceof Array || typeof maybeObject !== "object")
return maybeObject;
// https://stackoverflow.com/a/56833507
const definitelyObject: { [index: string]: any } = maybeObject;
const sortedKeys = Object.keys(definitelyObject).sort();
// https://gist.github.com/aleph-naught2tog/938dd20dfc53e91da952569fd5655e2d
return sortedKeys.reduce((objectSoFar, currentKey) => {
const currentValue: any = definitelyObject[currentKey];
const maybeSortedValue: any = order(currentValue);
return Object.setPrototypeOf({
...objectSoFar,
[currentKey]: maybeSortedValue === null ? 0 : maybeSortedValue
}, Object.getPrototypeOf(definitelyObject));
}, {});
};
export function searchObject(obj: LooseObject, searchItem: any, result?: LooseObject) {
result = {};
for (const key in obj) {
if (searchItem === obj[key])
result[key] = obj[key];
}
return result;
}
/// reference
// https://deno.land/std/fs
// https://deno.land/std/datetime
// https://deno.land/std/http
// https://deno.land/x/abc
// https://deno.land/x/frontmatter
// https://deno.land/x/minifier
// https://deno.land/x/rusty_markdown
// https://github.com/marktiedemann/deno-dart-sass
// https://github.com/cybertim/yandlebars