Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #5

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b8313e0
Add Docker files
cvn Feb 9, 2018
dad15f1
Update styles
cvn Feb 9, 2018
8bac0b3
Add support for online redirection
cvn Feb 9, 2018
f6ad4bb
Ensure alphabetical order on index page
cvn Feb 12, 2018
2332869
Fix encoding issues
cvn Feb 10, 2018
4beeeab
Add title and table of contents to index page
cvn Feb 12, 2018
ee201b4
Style curly brackets as colored text
cvn Feb 12, 2018
64c23e9
Update styles
cvn Feb 12, 2018
2db7fab
Fix online redirection
cvn Feb 12, 2018
c926e30
Fix text with underscores
cvn Feb 12, 2018
fc8573f
Bump version
cvn Feb 12, 2018
e97ee73
Use COPY instead of ADD in Dockerfile
cvn Feb 14, 2018
27ff4c8
Bump version
cvn Apr 4, 2018
1aa47fe
Change path matcher to handle new "pages" folders in tldr-pages repo
cvn Mar 28, 2019
3af791c
Bump version
cvn Mar 28, 2019
db381dd
Bump version
cvn Apr 27, 2020
801ed51
Bump version
cvn Oct 21, 2020
c7ed388
Bump version
cvn May 1, 2022
05b1eb7
Bump version
cvn Nov 8, 2022
54e93a2
Fix for tldr pages switching from master to main
cvn Oct 18, 2023
6a24af7
Update readme
cvn Oct 18, 2023
3f6cb04
Bump version
cvn Oct 18, 2023
2be92e4
Add github action for docset generation, WIP
cvn Oct 30, 2023
4a8df0e
ci: docker is installed on github runners already
cvn Oct 30, 2023
0158cbb
ci: use variable for the date string
cvn Oct 30, 2023
88a1ddc
ci: change sed syntax from bsd to linux
cvn Oct 30, 2023
6f1ad65
ci: files are not shared between jobs by default, so just use one job
cvn Oct 30, 2023
b3793ed
ci: github runner does not execute shell commands, use alternate env var
cvn Oct 30, 2023
77f38cd
ci: ensure branch is always updated
cvn Oct 30, 2023
481d75c
ci: fix author identity unknown error
cvn Oct 31, 2023
64b2e66
ci: fix variable expansion
cvn Oct 31, 2023
fb0e150
ci: refactor git commands for readability
cvn Oct 31, 2023
1b8b6bb
ci: whitespace, add comments
cvn Oct 31, 2023
5aa332a
ci: rename a few things
cvn Oct 31, 2023
1c772c8
ci: add step to create PR
cvn Oct 31, 2023
658bb96
ci: set upstream repo, break command into multiple lines
cvn Oct 31, 2023
61ed3e5
ci: fix PR command
cvn Nov 1, 2023
1988d4a
Update readme
cvn Nov 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/update-docset.yml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'

services:
builder:
build: .
volumes:
- .:/code
35 changes: 24 additions & 11 deletions generator.py
Original file line number Diff line number Diff line change
@@ -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><head><link rel="stylesheet" type="text/css" href="../style.css"/></head><body><section id="tldr"><div id="page">%content%</div></section></body></html>"""
html_tmpl = """<html><!-- Online page at {url} -->
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../style.css"/>
</head>
<body>
<section id="tldr">
<div id="page">{content}</div>
</section>
</body>
</html>"""

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)
Expand All @@ -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)
Expand All @@ -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'<em>\1</em>', 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('<html><head></head><body><h1>TLDR pages Docset</h1><br/>powered by <a href="http://tldr-pages.github.io">tldr-pages.github.io/</a>')
for dir in os.listdir(doc_path):
html.write('<html><!-- Online page at '+online_url+' --><head><meta charset="UTF-8"><title>TLDR pages</title></head><body><h1>TLDR pages</h1><br/>powered by <a href="http://tldr-pages.github.io">tldr-pages.github.io/</a>')
for dir in sorted(os.listdir(doc_path)):
if os.path.isdir(os.path.join(doc_path, dir)):
html.write("<h2>%s</h2><ul>" % dir)
html.writelines(['<li><a href="%s/%s">%s</a></li>' % (dir, f, f[:-5]) for f in os.listdir(os.path.join(doc_path, dir))])
html.write('<a name="//apple_ref/cpp/Section/{name}" class="dashAnchor"></a><h2>{name}</h2><ul>'.format(name=dir))
html.writelines(['<li><a href="%s/%s">%s</a></li>' % (dir, f, f[:-5]) for f in sorted(os.listdir(os.path.join(doc_path, dir)))])
html.write("</ul>")
html.write('</body></html>')

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
markdown2
4 changes: 3 additions & 1 deletion static/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>TLDR pages 0.0.2.8</string>
<string>TLDR pages YYYY-MM-DD</string>
<key>CFBundleName</key>
<string>TLDR pages</string>
<key>DocSetPlatformFamily</key>
Expand All @@ -12,5 +12,7 @@
<true/>
<key>dashIndexFilePath</key>
<string>index.html</string>
<key>DashDocSetFamily</key>
<string>dashtoc</string>
</dict>
</plist>
66 changes: 18 additions & 48 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand All @@ -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; } }