Skip to content

Commit

Permalink
Add replacements for pages' icons
Browse files Browse the repository at this point in the history
These are all icons used in pages today.  To migrate, replace the
`glyphicon: …` metadata entry by `icon: …`.
  • Loading branch information
lukasjuhrich committed Oct 9, 2023
1 parent cc04447 commit 78e4365
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions sipa/flatpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def hidden(self) -> bool:
"""
return self.localized_page.meta.get('hidden', False)

@property
def icon(self) -> str:
return self.localized_page.meta.get("icon") or self.localized_page.meta.get(
"glyphicon"
)

def __getattr__(self, attr: str) -> str:
"""Return the meta attribute of the localized page
Expand Down
31 changes: 31 additions & 0 deletions sipa/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ def init_app(app, **kwargs):
app.context_processor(inject_meetingcal)

app.add_template_filter(render_links)

def glyphicon_to_bi(glyphicon: str) -> str:
MAP = {
"glyphicon-briefcase": "bi-briefcase-fill",
"glyphicon-bullhorn": "bi-megaphone-fill",
"glyphicon-chevron-down": "bi-chevron-down",
"glyphicon-cloud": "bi-cloud-fill",
"glyphicon-comment": "bi-chat-left-fill",
"glyphicon-dashboard": "bi-speedometer",
"glyphicon-download-alt": "bi-download",
"glyphicon-envelope": "bi-envelope-fill",
"glyphicon-euro": "bi-currency-euro",
"glyphicon-file": "bi-file-earmark-fill",
"glyphicon-globe": "bi-globe-europe-africa",
"glyphicon-headphones": "bi-headphones",
"glyphicon-list-alt": "bi-card-list",
"glyphicon-lock": "bi-lock-fill",
"glyphicon-log-in": "bi-box-arrow-in-right",
"glyphicon-question-sign": "bi-question-circle-fill",
"glyphicon-retweet": "bi-arrow-repeat",
"glyphicon-signal": "bi-router-fill", # used for router page
"glyphicon-star": "bi-star-fill",
"glyphicon-tasks": "bi-box-arrow-up-right",
"glyphicon-tint": "bi-droplet-fill",
"glyphicon-transfer": "bi-arrow-left-right",
"glyphicon-user": "bi-person-fill",
"glyphicon-wrench": "bi-wrench-adjustable",
}
return MAP.get(glyphicon, glyphicon.replace("glyphicon-", "bi-"))

app.add_template_filter(glyphicon_to_bi)
logger.debug("Jinja globals have been set",
extra={'data': {'jinja_globals': app.jinja_env.globals}})

Expand Down
2 changes: 1 addition & 1 deletion sipa/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{%- for article in c.articles -%}
{%- if not article.id == 'index' and article.title and not article.hidden -%}
<a href="{{ url_for('pages.show', category_id=c.id, article_id=article.id) }}" class="dropdown-item">
<span class="bi-{{ article.glyphicon }}"></span>
<span class="{{ article.icon | glyphicon_to_bi }}"></span>
&nbsp; {{ article.title }}
</a>
{%- endif %}
Expand Down

0 comments on commit 78e4365

Please sign in to comment.