diff options
author | ng0 <ng0@n0.is> | 2019-11-12 21:37:15 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-11-12 21:37:15 +0000 |
commit | 1c6b6866bebf2659a15540bbbf7a4907e8ee0e8a (patch) | |
tree | 736bff1a49fd88c9c14c72a1e5340437928382f7 /sitemap.py | |
download | www_shared-1c6b6866bebf2659a15540bbbf7a4907e8ee0e8a.tar.gz www_shared-1c6b6866bebf2659a15540bbbf7a4907e8ee0e8a.zip |
init from www.git
Diffstat (limited to 'sitemap.py')
-rw-r--r-- | sitemap.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sitemap.py b/sitemap.py new file mode 100644 index 0000000..5ccf744 --- /dev/null +++ b/sitemap.py | |||
@@ -0,0 +1,21 @@ | |||
1 | import os | ||
2 | from pathlib import Path, PurePosixPath | ||
3 | |||
4 | |||
5 | def sitemap_tree(path): | ||
6 | tree = dict(name=PurePosixPath(path).name, children=[]) | ||
7 | try: | ||
8 | mylist = os.listdir(path) | ||
9 | except OSError: | ||
10 | pass | ||
11 | else: | ||
12 | for name in mylist: | ||
13 | fn = os.path.join(path, name) | ||
14 | if os.path.isdir(fn): | ||
15 | tree['children'].append(sitemap_tree(fn)) | ||
16 | else: | ||
17 | np = os.path.join(name) | ||
18 | if np.startswith('/'): | ||
19 | np = np[1:] | ||
20 | tree['children'].append(dict(name=np)) | ||
21 | return tree | ||