on master help sign in
docs: remove former utilities, metadata
commitb267a129101fee6f681efb14a6bc5c647acb25a1 authorMatilde Park <matilde@tlon.io> dateWed 16 Jun 2021, 16:25 (5 years ago) parentb69b81d
7 files changed+6−189
content/docs/.gitignore−4 content/docs/.gitmodules−3 content/docs/LICENSE−21 content/docs/README.markdown−3 content/docs/anchors.py−135 content/docs/weights.sh−23 package-lock.json+6
content/docs/.gitignoredeleted−4
@@ -1,4 +0,0 @@
1−# OS
2−.DS_Store
3−# etc
4−*.swn
content/docs/.gitmodulesdeleted−3
@@ -1,3 +0,0 @@
1−[submodule "docs/hoon/workbook"]
2− path = docs/hoon/workbook
3− url = git@github.com:urbit/hoon-workbook.git
content/docs/LICENSEdeleted−21
@@ -1,21 +0,0 @@
1−MIT License
2−
3−Copyright (c) 2019 Tlon Corporation
4−
5−Permission is hereby granted, free of charge, to any person obtaining a copy
6−of this software and associated documentation files (the "Software"), to deal
7−in the Software without restriction, including without limitation the rights
8−to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9−copies of the Software, and to permit persons to whom the Software is
10−furnished to do so, subject to the following conditions:
11−
12−The above copyright notice and this permission notice shall be included in all
13−copies or substantial portions of the Software.
14−
15−THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16−IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17−FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18−AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19−LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20−OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21−SOFTWARE.
content/docs/README.markdowndeleted−3
@@ -1,3 +0,0 @@
1−# Urbit Docs
2−
3−Urbit documentation as it appears on [urbit.org](https://urbit.org/docs/).
content/docs/anchors.pydeleted−135
@@ -1,135 +0,0 @@
1−#!/usr/bin/env python3
2−
3−import os
4−import sys
5−from pathlib import Path
6−from typing import List, Tuple
7−
8−
9−# inspired by weights.sh
10−
11−# NOTE: This script does not prevent you from shooting yourself in the foot.
12−# If you manually set a bogus value for insert_anchor_links it will not fix it for you
13−"""
14−1. get a list of all .md files
15−2. for each md file
16− a. get front matter
17− b. get value of key `insert_anchor_links`, default to none if not present
18− c. output a tuple of (setting, file)
19−3. accumulate all anchor setting values for all md files
20−4. write tuple to 'anchors' file, prompt to edit, open in preferred editor
21−5. once prompt is answered, read back file
22−6. read edited 'anchors' file, overwrite new setting for each file
23−"""
24−
25−ANCHOR_KEY = "insert_anchor_links = "
26−ANCHOR_FILE = "anchors"
27−
28−def nth_occurrence(arr, target_value, wanted_idx):
29− return [idx for idx, val in enumerate(arr) if val == target_value][wanted_idx - 1]
30−
31−def validate_entry(setting: str, file: str):
32− if not setting in ["left", "right", "none"]:
33− sys.exit(f"Invalid setting '{setting}' provided for file '{file}'")
34−
35−
36−def find_all_mds() -> List[str]:
37− # the `insert_anchor_links` is only applicable on `_index.md` files (i.e. sections)
38− return [str(p) for p in Path('./').rglob('**/.md')]
39−
40−def setting_from_frontmatter(lines: List[str]) -> str:
41− # 'insert_anchor_links = "none"' -> 'none'
42− for line in lines:
43− if line.startswith(ANCHOR_KEY):
44− # 1. 'insert_anchor_links = "none"\n'
45− # 2. ['insert_anchor_links = ' '"none"\n'][1] => '"none"\n'
46− # 3. "none\n"
47− # 4. "none"
48− return line \
49− .split(ANCHOR_KEY)[1] \
50− .replace('\"', '') \
51− .replace('\n', '')
52−
53− return "none" # default setting if key not present
54−
55−def anchors_from_frontmatter(md_files: List[str]) -> List[Tuple[str, str]]:
56− # returns tuple(setting, file)
57− anchor_settings = []
58−
59− for md_file in md_files:
60− with open(md_file, "r") as f:
61− lines = f.readlines()
62− setting = setting_from_frontmatter(lines)
63− anchor_settings.append((setting, md_file))
64−
65− return anchor_settings
66−
67−def write_anchor_file(anchor_settings: List[Tuple[str, str]]):
68− with open(ANCHOR_FILE, "w+") as f:
69− for setting, file in anchor_settings:
70− f.write(f"{setting} {file}\n")
71−
72−
73−def prompt_editor():
74− editor = os.getenv('EDITOR', 'nano')
75− os.system(f"{editor} {ANCHOR_FILE}")
76− input("Edit the anchor settings and press enter...")
77−
78−def read_anchor_file() -> List[Tuple[str, str]]:
79− anchor_settings = []
80−
81− with open(ANCHOR_FILE, "r") as f:
82− for line in f:
83− line = line.replace('\n', '')
84− setting, file = line.split(' ')
85− anchor_settings.append((setting, file))
86−
87− return anchor_settings
88−
89−
90−def write_entry(setting: str, file: str):
91− validate_entry(setting, file)
92−
93−
94− # not optimized
95− with open(file, "r+") as f:
96− lines = f.readlines()
97− # lines = list(filter(bool, text.split('\n'))) # split text by lines,
98− fm_end = nth_occurrence(lines, "+++\n", 2) # get index of end of front matter (signaled by second '+++')
99−
100− # remove existing setting if it exists
101− for line in lines[:fm_end]:
102− if line.startswith(ANCHOR_KEY):
103− lines.remove(line)
104− fm_end -= 1 # correct the index for the removal
105−
106− if setting != "none":
107− # by default, there is no need to specify "none"
108− lines.insert(fm_end, ANCHOR_KEY + f'"{setting}"' + '\n') # insert the setting right before the end of front matter
109− f.seek(0) # go to beginning of file
110− f.writelines(lines) # overwrite with new contents
111− f.truncate() # idk why but necessary for bug-free behviour (otherwise it adds excess newlines and stuff)
112−
113−
114−
115−def anchors_to_frontmatter(anchor_settings: List[Tuple[str, str]]):
116− for setting, file in anchor_settings:
117− write_entry(setting, file)
118−
119−def cleanup():
120− os.remove("anchors")
121−
122−
123−def main():
124− files = find_all_mds()
125− print(f'found {len(files)} .md files')
126− write_anchor_file(anchors_from_frontmatter(files))
127− prompt_editor()
128− anchors_to_frontmatter(read_anchor_file())
129− cleanup()
130− print('done')
131−
132−
133−if __name__ == '__main__':
134− main()
135−
content/docs/weights.shdeleted−23
@@ -1,23 +0,0 @@
1−#!/bin/bash
2−
3−EDITOR=${EDITOR:-atom}
4−
5−# build weights file
6−for file in $(find -type f -name \*.md); do
7− [[ $file == *_index.md ]] && continue
8− echo $(grep -m 1 "weight = " $file | sed 's/^weight = //') $file
9−done | sort -n > weights
10−
11−# edit weights file
12−$EDITOR weights
13−read -p "Edit weights and press enter to continue..."
14−
15−# for each line in weights file, read values weight and file, and update
16−# $weight in $file
17−cat weights | while read weight file; do
18− echo $weight $file
19− sed -i'' "s/^weight = [.0-9]*/weight = $weight/" $file
20−done
21−
22−# remove weights file
23−rm weights
package-lock.json+6
@@ -1395,6 +1395,12 @@
13951395 "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==",
13961396 "dev": true
13971397 },
1398+ "husky": {
1399+ "version": "6.0.0",
1400+ "resolved": "https://registry.npmjs.org/husky/-/husky-6.0.0.tgz",
1401+ "integrity": "sha512-SQS2gDTB7tBN486QSoKPKQItZw97BMOd+Kdb6ghfpBc0yXyzrddI0oDV5MkDAbuB4X2mO3/nj60TRMcYxwzZeQ==",
1402+ "dev": true
1403+ },
13981404 "iconv-lite": {
13991405 "version": "0.6.3",
14001406 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",