From 361ba0c32b0f2b4ed141a0dd00bc901320964cd9 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sat, 15 Jun 2019 12:30:11 +0200 Subject: [PATCH] Add a GitHub style repository card on index page (#620) --- blog/before_build.py | 18 ++++++++- blog/static/css/main.css | 51 ++++++++++++++++++++++++ blog/templates/auto/forks.html | 0 blog/templates/auto/recent-updates.html | 0 blog/templates/auto/stars.html | 0 blog/templates/first-edition/index.html | 2 +- blog/templates/recent-updates.html | 1 - blog/templates/second-edition/index.html | 34 +++++++++++++++- 8 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 blog/templates/auto/forks.html create mode 100644 blog/templates/auto/recent-updates.html create mode 100644 blog/templates/auto/stars.html delete mode 100644 blog/templates/recent-updates.html diff --git a/blog/before_build.py b/blog/before_build.py index 40fa16bd..b779889e 100644 --- a/blog/before_build.py +++ b/blog/before_build.py @@ -12,7 +12,13 @@ one_month_ago = datetime.now() - timedelta(days=32) def filter_date(issue): return issue.closed_at > one_month_ago -with io.open("templates/recent-updates.html", 'w', encoding='utf8') as recent_updates: +def format_number(number): + if number > 1000: + return u"{:.1f}k".format(float(number) / 1000) + else: + return u"{}".format(number) + +with io.open("templates/auto/recent-updates.html", 'w', encoding='utf8') as recent_updates: recent_updates.truncate() recent_updates.write(u"") + +repo = g.get_repo("phil-opp/blog_os") + +with io.open("templates/auto/stars.html", 'w', encoding='utf8') as stars: + stars.truncate() + stars.write(format_number(repo.stargazers_count)) + +with io.open("templates/auto/forks.html", 'w', encoding='utf8') as forks: + forks.truncate() + forks.write(format_number(repo.forks_count)) diff --git a/blog/static/css/main.css b/blog/static/css/main.css index 714a0562..39a21d64 100644 --- a/blog/static/css/main.css +++ b/blog/static/css/main.css @@ -220,6 +220,7 @@ aside#all-posts-link { aside#recent-updates { position: absolute; + min-width: 11rem; max-width: 17rem; top: 4rem; margin-left: 45rem; @@ -227,6 +228,10 @@ aside#all-posts-link { font-size: 90%; } + aside#recent-updates .block { + margin-bottom: 1.5rem; + } + aside#recent-updates h2 { font-size: 110%; margin-bottom: .2rem; @@ -331,3 +336,49 @@ details summary { details summary h3, details summary h4, details summary h5, details summary h6 { display: inline; } + +.gh-repo-box { + border: 1px solid #d1d5da; + border-radius: 3px; + padding: 16px; + margin-top: 0.5rem; + color: #586069; + font-size: 80%; +} + +.gh-repo-box .repo-link { + color: #0366d6; + font-weight: 600; + font-size: 120%; +} + +.gh-repo-box .subtitle { + margin-bottom: 16px; +} + +.gh-repo-box .stars-forks { + margin-bottom: 0; +} + +.gh-repo-box .stars-forks a { + color: #586069; +} + +.gh-repo-box .stars-forks a:hover { + color: #0366d6; + text-decoration: none; +} + +.gh-repo-box .stars-forks svg { + vertical-align: text-bottom; + fill: currentColor; +} + +.gh-repo-box .stars { + display: inline-block; +} + +.gh-repo-box .forks { + display: inline-block; + margin-left: 16px; +} diff --git a/blog/templates/auto/forks.html b/blog/templates/auto/forks.html new file mode 100644 index 00000000..e69de29b diff --git a/blog/templates/auto/recent-updates.html b/blog/templates/auto/recent-updates.html new file mode 100644 index 00000000..e69de29b diff --git a/blog/templates/auto/stars.html b/blog/templates/auto/stars.html new file mode 100644 index 00000000..e69de29b diff --git a/blog/templates/first-edition/index.html b/blog/templates/first-edition/index.html index 22a3a33f..ab9de2f6 100644 --- a/blog/templates/first-edition/index.html +++ b/blog/templates/first-edition/index.html @@ -61,7 +61,7 @@ {% endblock main %} diff --git a/blog/templates/recent-updates.html b/blog/templates/recent-updates.html deleted file mode 100644 index 8b137891..00000000 --- a/blog/templates/recent-updates.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/blog/templates/second-edition/index.html b/blog/templates/second-edition/index.html index 3ca90866..b7fd6361 100644 --- a/blog/templates/second-edition/index.html +++ b/blog/templates/second-edition/index.html @@ -77,8 +77,38 @@ {% endblock main %}