Skip to content

Commit

Permalink
Add support for per-app shortcut icons
Browse files Browse the repository at this point in the history
Browsers ususally use these icons when displaying bookmarked
URLs. Varying them helps distinguish one app from another. When not
specified, the default icon is the one in apps/shared.
  • Loading branch information
lovett committed Dec 1, 2019
1 parent e0599ae commit eea3446
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions .ackrc
Expand Up @@ -4,6 +4,7 @@
--ignore-dir=htmlcov
--ignore-dir=logs
--ignore-dir=db
--ignore-dir=storage
--ignore-dir=.mypy_cache
--ignore-dir=__pycache__
--ignore-file=ext:pyc
Expand Down
24 changes: 17 additions & 7 deletions Makefile
Expand Up @@ -12,6 +12,11 @@ APPS := $(notdir $(APPS))
APPS := $(filter-out __%,$(APPS))
APPS := $(addprefix apps., $(APPS))

# A list of app-specific icons.
APP_ICONS := $(wildcard apps/*/static/app-icon.svg)
APP_ICONS := $(patsubst %.svg,%.png,$(APP_ICONS))


# A list of parsers with test suites in the form "parsers.[name of parser]".
PARSERS := $(wildcard parsers/*_test.py)
PARSERS := $(notdir $(PARSERS))
Expand All @@ -32,7 +37,6 @@ REQUIREMENTS_TEMP := $(CURDIR)/temp-requirements.txt
PIP_OUTDATED_TEMP := temp-pip-outdated.txt

SHARED_JS_DIR := $(CURDIR)/apps/shared/static/js
FAVICON_DIR := $(CURDIR)/apps/shared/static/favicon
TMUX_SESSION_NAME := medley

vpath %.cov coverage
Expand Down Expand Up @@ -316,13 +320,12 @@ hooks: dummy


favicon: dummy
convert -density 900 -background none -geometry 360x360 $(FAVICON_DIR)/app-icon.svg $(FAVICON_DIR)/app-icon.png
convert -density 900 -background none -geometry 48x48 $(FAVICON_DIR)/app-icon.svg temp-48.png
convert -density 900 -background none -geometry 32x32 $(FAVICON_DIR)/app-icon.svg temp-32.png
convert -density 900 -background none -geometry 16x16 $(FAVICON_DIR)/app-icon.svg temp-16.png
convert temp-16.png temp-32.png temp-48.png apps/shared/static/favicon/favicon.ico
convert -density 900 -background none -geometry 48x48 apps/shared/static/app-icon.svg temp-48.png
convert -density 900 -background none -geometry 32x32 apps/shared/static/app-icon.svg temp-32.png
convert -density 900 -background none -geometry 16x16 apps/shared/static/app-icon.svg temp-16.png
convert temp-16.png temp-32.png temp-48.png apps/shared/static/favicon.ico
rm temp-48.png temp-32.png temp-16.png
cd $(FAVICON_DIR) && optipng -quiet -o 3 *.png
cd apps/shared/static && optipng -quiet -o 3 *.png

# Automation for merging changes from the master branch into the
# production branch.
Expand Down Expand Up @@ -362,3 +365,10 @@ reset:
rm -r coverage
rm -r htmlcov
rm .coverage

# Render an app icon SVG to PNG.
$(APP_ICONS):
convert -density 900 -background none -geometry 360x360 $(patsubst %.png, %.svg, $@) $@

# Geneate PNGs for all app icon SVGs.
app-icons: $(APP_ICONS)
Binary file added apps/alturl/static/app-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions apps/alturl/static/app-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/reminder/reminder.jinja.html
@@ -1,6 +1,10 @@
{% extends "base.jinja.html" %}
{% import "macros.jinja.html" as macros -%}

{% block app_icon -%}
{{ macros.appSpecificIcon(app_url) }}
{%- endblock %}

{% block stylesheets %}
{{ macros.staticAsset('reminder', 'reminder.css') }}
{% endblock %}
Expand Down
Binary file added apps/reminder/static/app-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions apps/reminder/static/app-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes.
Binary file added apps/weather/static/app-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions apps/weather/static/app-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions apps/weather/weather.jinja.html
@@ -1,4 +1,9 @@
{% extends "base.jinja.html" %}
{% import "macros.jinja.html" as macros -%}

{% block app_icon -%}
{{ macros.appSpecificIcon(app_url) }}
{%- endblock %}

{% block page_body %}
<main>
Expand Down
2 changes: 1 addition & 1 deletion medley.py
Expand Up @@ -144,7 +144,7 @@ def setup() -> None:
app_config["/favicon.ico"] = {
"tools.staticfile.on": True,
"tools.staticfile.filename": os.path.realpath(
"./apps/shared/static/favicon/favicon.ico"
"./apps/shared/static/favicon.ico"
),
}

Expand Down
6 changes: 4 additions & 2 deletions templates/base.jinja.html
Expand Up @@ -22,8 +22,10 @@

{% block stylesheets %}{% endblock %}

<link rel="apple-touch-icon" href="/shared/static/favicon/app-icon.png"/>
<link rel="mask-icon" href="/shared/static/favicon/app-icon.svg" color="black">
{% block app_icon -%}
<link rel="shortcut icon" href="/shared/static/app-icon.png" />
<link rel="mask-icon" href="/shared/static/app-icon.svg" color="black">
{%- endblock %}

<meta name="medley-home" content="{{ '/' | internal_url }}" />
<meta name="medley-startpage" content="{{ '/startpage' | internal_url }}" />
Expand Down
5 changes: 5 additions & 0 deletions templates/macros.jinja.html
Expand Up @@ -248,3 +248,8 @@
{% endif %}
</section>
{%- endmacro -%}

{% macro appSpecificIcon(app_url) -%}
<link rel="shortcut icon" href="{{ app_url }}/static/app-icon.png" />
<link rel="mask-icon" href="{{ app_url }}/static/app-icon.svg" color="black">
{%- endmacro %}

0 comments on commit eea3446

Please sign in to comment.