feat: add notes share
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
3a63a9ee57
commit
c86b7b3480
|
@ -0,0 +1 @@
|
|||
# 筆記分享
|
|
@ -0,0 +1 @@
|
|||
* [Overview]()
|
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Document</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Description">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css" title="docsify-darklight-theme" type="text/css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'Document Collections',
|
||||
repo: '',
|
||||
loadSidebar: true,
|
||||
subMaxLevel: 3,
|
||||
//loadNavbar: true,
|
||||
relativePath: true,
|
||||
fallbackLanguages: ['en'],
|
||||
|
||||
// force browser to get lateast document
|
||||
requestHeaders: {
|
||||
'cache-control': 'max-age=0',
|
||||
},
|
||||
|
||||
|
||||
//tabs extension
|
||||
tabs: {
|
||||
persist : true, // default
|
||||
sync : true, // default
|
||||
theme : 'classic', // default
|
||||
tabComments: true, // default
|
||||
tabHeadings: true // default
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify@4.12.1/lib/docsify.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify-tabs@1.5.0/dist/docsify-tabs.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-python.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-json.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-yaml.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-bash.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-ini.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-go.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-scheme.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-docker.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-git.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-nginx.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.24.1/components/prism-xml-doc.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,105 @@
|
|||
import os
|
||||
import glob
|
||||
import sys
|
||||
from urllib.parse import quote
|
||||
|
||||
import platform
|
||||
|
||||
|
||||
path_split = '/'
|
||||
if platform.system() == 'Windows':
|
||||
path_split = '\\'
|
||||
|
||||
|
||||
IGNORE = [
|
||||
'src',
|
||||
'.git',
|
||||
'vendor',
|
||||
'docs',
|
||||
'assets',
|
||||
"README.md",
|
||||
]
|
||||
HEADER = [
|
||||
"* [Overview]()"
|
||||
]
|
||||
FOOTER = [
|
||||
"",
|
||||
"<br><br>",
|
||||
"",
|
||||
"* [Back](../)"
|
||||
]
|
||||
|
||||
def make_display_name(name):
|
||||
name = name.split(".md")[0] # Remove .md extension
|
||||
name = name.replace('-', ' ') # Add space instead of -
|
||||
name = name.replace('_', ' ') # Add space instead of _
|
||||
# Capitalize all words
|
||||
# (Exclude some words from capitalization)
|
||||
forbidden = ['a', 'on', 'to', 'and', 'with', 'how', 'at', 'the']
|
||||
capitalized = ''
|
||||
for word in name.split(' '):
|
||||
if (word.lower() not in forbidden):
|
||||
capitalized += word[0].upper() + word[1:]
|
||||
# capitalized += word.capitalize()
|
||||
else:
|
||||
capitalized += word.lower()
|
||||
capitalized += ' '
|
||||
name = capitalized.strip()
|
||||
|
||||
return name
|
||||
|
||||
def generate_sidebar(path, entries):
|
||||
print(path)
|
||||
sidebar_file = open(os.path.join(path,'_sidebar.md'), 'w', encoding="utf-8")
|
||||
for entry in entries:
|
||||
sidebar_file.write(entry+'\n')
|
||||
sidebar_file.close()
|
||||
|
||||
def acceptfile(name):
|
||||
if os.path.splitext(name)[1] != ".md": return False
|
||||
if name in IGNORE: return False
|
||||
if name.startswith('.') or name.startswith('_'): return False
|
||||
return True
|
||||
|
||||
def acceptdir(root,d):
|
||||
if d in IGNORE: return False
|
||||
# if not acceptroot(root): return False
|
||||
if os.path.exists(os.path.join(root,d,'README.md')): return True
|
||||
return False
|
||||
|
||||
def acceptroot(root):
|
||||
parts = root.split(path_split)
|
||||
if len(parts) > 1:
|
||||
for part in parts:
|
||||
if part in IGNORE: return False
|
||||
return True
|
||||
|
||||
def scan_dir(path="."):
|
||||
for root, dirs, files in os.walk(path):
|
||||
dirs = sorted(dirs)
|
||||
files = sorted(files)
|
||||
entries = []
|
||||
if len(root.split(path_split)) == 1:
|
||||
entries += HEADER
|
||||
elif not acceptroot(root): continue
|
||||
else:
|
||||
entries.append("* [{}]()".format(make_display_name(root.split(path_split)[-1])) )
|
||||
stop = []
|
||||
for d in dirs:
|
||||
if not acceptdir(root,d):
|
||||
stop.append(d)
|
||||
continue
|
||||
entries.append("* [{}](./{}/)".format(make_display_name(d), quote(d)))
|
||||
for d in stop:
|
||||
dirs.remove(d)
|
||||
for f in files:
|
||||
if not acceptfile(f): continue
|
||||
entries.append("* [{}]({})".format(make_display_name(f), quote(f)))
|
||||
if len(root.split(path_split)) > 1:
|
||||
entries += FOOTER
|
||||
generate_sidebar(root, entries)
|
||||
|
||||
if __name__ == "__main__":
|
||||
scan_dir()
|
||||
|
||||
print('✅ All done!')
|
Loading…
Reference in New Issue