-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsvdocs.py
More file actions
66 lines (50 loc) · 1.65 KB
/
svdocs.py
File metadata and controls
66 lines (50 loc) · 1.65 KB
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
#!/usr/bin/env python3
import json
import os
import sys
from pypub.epub import create_epub_from_htmls
from pypub.utils import get_soup
AUTHOR = "Svelte Team"
BASE_URL = "https://svelte.dev"
def docs_to_epub(root_url, output_filename, title):
soup = get_soup(root_url)
sidebar = soup.find("ul", class_="sidebar")
li_tags = [li for li in sidebar.children if li.name == "li"]
chapter_urls = []
for li_tag in li_tags:
section_title = li_tag.find("h3").text.strip()
# print(f"Section: {section_title}")
a_tags = li_tag.find_all("a", class_="page")
for a_tag in a_tags:
page_title = a_tag.text.strip()
chapter_url = f"{BASE_URL}{a_tag['href']}"
# print(f"\t{page_title} ({chapter_url})")
chapter_urls.append(chapter_url)
# print(f"Found {len(chapter_html_paths)} chapters.")
create_epub_from_htmls(
chapter_urls,
output_filename=output_filename,
title=title,
author=AUTHOR
)
def create_docs_epub(doc_name: str = "main"):
match doc_name:
case 'kit':
docs_to_epub("https://svelte.dev/docs/kit/introduction", output_filename="sveltekit-docs.epub", title="SvelteKit Docs")
case 'cli':
docs_to_epub("https://svelte.dev/docs/cli/overview", output_filename="svelte-cli-docs.epub", title="Svelte CLI Docs")
case 'main':
docs_to_epub("https://svelte.dev/docs/svelte/overview", output_filename="svelte-docs.epub", title="Svelte Docs")
case _:
print(f"Unknown doc name: '{doc_name}'")
def main():
args = sys.argv[1:]
doc_name = args[0] if len(args) else 'main'
if doc_name == "all":
create_docs_epub('main')
create_docs_epub('kit')
create_docs_epub('cli')
else:
create_docs_epub(doc_name)
if __name__ == '__main__':
main()