diff --git a/.github/workflows/update-docset.yml b/.github/workflows/update-docset.yml
new file mode 100644
index 0000000..733051a
--- /dev/null
+++ b/.github/workflows/update-docset.yml
@@ -0,0 +1,68 @@
+name: Update Docset
+
+on:
+ schedule:
+ - cron: '0 0 1 * *'
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Create version environment variable
+ run: echo "new_version=$(date -u +%Y-%m-%d)" >> $GITHUB_ENV
+
+
+ # Build docset
+
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Set version number
+ run: sed -i "s/YYYY-MM-DD/$new_version/" static/Info.plist
+
+ - name: Build docset
+ run: docker compose up
+
+
+ # Create PR
+
+ - name: Sync contributions repo
+ run: gh repo sync cvn/Dash-User-Contributions -b master --force
+ env:
+ GITHUB_TOKEN: ${{ secrets.DASH_REPO_TOKEN }}
+
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ repository: cvn/Dash-User-Contributions
+ token: ${{ secrets.DASH_REPO_TOKEN }}
+ path: Dash-User-Contributions
+
+ - name: Update version number in docset.json
+ run: |
+ sed -i "s/\"version\": \".*\"/\"version\": \"$new_version\"/" Dash-User-Contributions/docsets/tldr/docset.json
+
+ - name: Move docset
+ run: mv tldr_pages.tgz Dash-User-Contributions/docsets/tldr/
+
+ - name: Commit changes
+ run: |
+ cd Dash-User-Contributions
+ git config user.name "github-actions[bot]"
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ git checkout -b tldr-update
+ git add --all .
+ git commit -m "Update TLDR pages docset to $new_version"
+ git push --force origin tldr-update
+
+ - name: Create pull request to upstream
+ run: |
+ cd Dash-User-Contributions
+ gh pr create \
+ --repo Kapeli/Dash-User-Contributions \
+ --head cvn:tldr-update \
+ --title "Update TLDR pages docset to $new_version" \
+ --body "This is an automated update created by [a workflow](https://github.com/cvn/tldr-python-dash-docset/actions/workflows/update-docset.yml)."
+ env:
+ GITHUB_TOKEN: ${{ secrets.DASH_REPO_TOKEN }}
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..4ffa7fe
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,9 @@
+FROM python:3
+
+RUN mkdir /code
+COPY requirements.txt /code/
+WORKDIR /code
+RUN pip install -r requirements.txt
+COPY . /code/
+
+CMD python generator.py
diff --git a/README.md b/README.md
index cd9523b..bb22893 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,25 @@ user manual.
Thanks to [tldr.jsx][4] for your great CSS!
+### This is a fork
+
+The original author of this project, [Moddus](https://github.com/Moddus/tldr-python-dash-docset), appears to have abandoned it. This fork contains some [bug fixes and small improvements](https://github.com/Moddus/tldr-python-dash-docset/pull/5) to the original.
+
+### Build
+
+If you have python 3 and the [required packages](requirements.txt):
+
+ python generator.py
+
+Or use Docker to create an environment and build:
+
+ docker compose up
+
+### Updating Dash
+
+This repo has [a workflow](https://github.com/cvn/tldr-python-dash-docset/actions/workflows/update-docset.yml) that regularly updates the docset in Dash.
+
+
[1]: http://kapeli.com/dash
[2]: http://zealdocs.org/
[3]: https://github.com/tldr-pages/tldr
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..442f526
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,7 @@
+version: '2'
+
+services:
+ builder:
+ build: .
+ volumes:
+ - .:/code
diff --git a/generator.py b/generator.py
index d4076ad..4b057c5 100755
--- a/generator.py
+++ b/generator.py
@@ -1,15 +1,27 @@
#!/usr/bin/env python3
import requests as req, zipfile, io, markdown2 as md, sqlite3, os, shutil, tarfile
+import re
-html_tmpl = """
"""
+html_tmpl = """
+
+
+
+
+
+
+
+"""
-doc_source = "https://github.com/tldr-pages/tldr/archive/master.zip"
+online_url = "https://github.com/tldr-pages/tldr/blob/main/pages"
+doc_source = "https://github.com/tldr-pages/tldr/archive/refs/heads/main.zip"
docset_path = "tldrpages.docset"
doc_path_contents = docset_path + "/Contents/"
doc_path_resources = docset_path + "/Contents/Resources/"
doc_path = docset_path + "/Contents/Resources/Documents/"
-doc_pref = "tldr-master/pages"
+doc_pref = "tldr-main/pages/"
if os.path.exists(doc_path):
try: shutil.rmtree(doc_path)
@@ -36,12 +48,12 @@
cur.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
# Generate tldr pages to HTML documents
-markdowner = md.Markdown()
+markdowner = md.Markdown(extras=["code-friendly"])
with zipfile.ZipFile(io.BytesIO(r.content), "r") as archive:
for path in archive.namelist():
if path.startswith(doc_pref) and path.endswith(".md"):
cmd_name = path[path.rfind("/")+1:-3]
- sub_dir = path[len(doc_pref)+1:path.rfind("/")]
+ sub_dir = path[len(doc_pref):path.rfind("/")]
sub_path = os.path.join(doc_path, sub_dir)
if not os.path.exists(sub_path):
try: os.mkdir(sub_path)
@@ -54,19 +66,20 @@
else:
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (cmd_name, 'Command', sub_dir+'/'+cmd_name+".html"))
doc = markdowner.convert(archive.read(path))
- doc = html_tmpl.replace("%content%", doc)
- with open(os.path.join(doc_path, path[len(doc_pref)+1:].replace(".md", ".html")), "wb") as html:
+ doc = re.sub(r'{{(.*?)}}', r'\1', doc)
+ doc = html_tmpl.format(url=online_url+'/'+sub_dir+'/'+cmd_name+'.md', content=doc)
+ with open(os.path.join(doc_path, path[len(doc_pref):].replace(".md", ".html")), "wb") as html:
html.write(doc.encode("utf-8"))
db.commit()
db.close()
# Generate tldr pages index.html
with open(os.path.join(doc_path, "index.html"), "w+") as html:
- html.write('TLDR pages Docset
powered by tldr-pages.github.io/')
- for dir in os.listdir(doc_path):
+ html.write('TLDR pagesTLDR pages
powered by tldr-pages.github.io/')
+ for dir in sorted(os.listdir(doc_path)):
if os.path.isdir(os.path.join(doc_path, dir)):
- html.write("%s
" % dir)
- html.writelines(['- %s
' % (dir, f, f[:-5]) for f in os.listdir(os.path.join(doc_path, dir))])
+ html.write('{name}
'.format(name=dir))
+ html.writelines(['- %s
' % (dir, f, f[:-5]) for f in sorted(os.listdir(os.path.join(doc_path, dir)))])
html.write("
")
html.write('')
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..746027a
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+requests
+markdown2
diff --git a/static/Info.plist b/static/Info.plist
index 65f5a2a..61d3ffa 100644
--- a/static/Info.plist
+++ b/static/Info.plist
@@ -3,7 +3,7 @@
CFBundleIdentifier
- TLDR pages 0.0.2.8
+ TLDR pages YYYY-MM-DD
CFBundleName
TLDR pages
DocSetPlatformFamily
@@ -12,5 +12,7 @@
dashIndexFilePath
index.html
+ DashDocSetFamily
+ dashtoc
diff --git a/static/style.css b/static/style.css
index 9ce4c6d..9424017 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,48 +1,16 @@
-* {
- font-family: Helvetica Neue, Helvetica;
- font-size: 1em; }
-
body {
+ font-family: Helvetica Neue, Helvetica, sans-serif;
+ font-size: 16px;
margin: 0;
background: #FEFEFE;
color: #151515; }
-.github-corner {
- border: 0;
- fill: #FEFEFE;
- position: fixed;
- right: 0;
- top: 0;
- z-index: 99;
- padding: 0.5em; }
- @media only screen and (min-device-width: 1024px) and (min-device-height: 728px) {
- .github-corner {
- padding: 0.2em; } }
+code em {
+ color: lightseagreen;
+ font-style: normal; }
-#tldr #search-bar {
- font-size: 1.5em;
- background-color: #151515;
- color: #FEFEFE;
- padding: 0.5em;
- position: fixed;
- top: 0;
- left: 0;
- width: 100%; }
- #tldr #search-bar * {
- font-family: "Source Code Pro", courier new, courier; }
- #tldr #search-bar input, #tldr #search-bar input:focus {
- border: none;
- outline: none;
- background-color: #151515;
- color: #FEFEFE; }
- @media only screen and (orientation: landscape) {
- #tldr #search-bar {
- font-size: 2em; } }
- @media only screen and (min-device-width: 1024px) and (min-device-height: 728px) {
- #tldr #search-bar {
- font-size: 1em; } }
#tldr #page {
- font-size: 1.25em;}
+ margin-bottom: 4em; }
#tldr #page p {
margin: 0; }
#tldr #page h1 {
@@ -51,12 +19,15 @@ body {
#tldr #page blockquote {
margin: 0 0.55em; }
#tldr #page code {
- font-family: "Source Code Pro", courier new, courier;
+ font-family: "Source Code Pro", courier new, courier, monospace;
background-color: #f2f2f2;
color: #212121;
- display: block;
- padding: 0.55em 1.25em;
+ display: inline-block;
+ padding: 0.25em 0.5em;
margin: 0; }
+ #tldr #page > p code {
+ display: block;
+ padding: 0.55em; }
#tldr #page ul {
list-style: none;
padding: 0 !important;
@@ -65,12 +36,11 @@ body {
padding: 0.5em 0.55em;
line-height: 1.1; }
@media only screen and (min-device-width: 1024px) {
- #tldr #page {
- font-size: 1em; }
- #tldr #page code {
+ #tldr #page > p code {
+ padding-left: 3em; }
+ #tldr #page ul li {
padding-left: 3em; }
#tldr #page ul li:before {
- content: "*";
- padding: 0 12px; } }
-
-/*# sourceMappingURL=index.css.map */
+ content: "–";
+ position: absolute;
+ margin-left: -1.5em; } }