mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-09-08 19:27:18 +02:00
Different optimations and bugs
This commit is contained in:
58
roles/docker-portfolio/filter_plugins/simpleicons_source.py
Normal file
58
roles/docker-portfolio/filter_plugins/simpleicons_source.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import requests
|
||||
import re
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
|
||||
def slugify(name):
|
||||
"""Convert a display name to a simple-icons slug format."""
|
||||
# Replace spaces and uppercase letters
|
||||
return re.sub(r'\s+', '-', name.strip().lower())
|
||||
|
||||
|
||||
def add_simpleicon_source(cards, domains, web_protocol='https'):
|
||||
"""
|
||||
For each card in portfolio_cards, check if an icon exists in the simpleicons server.
|
||||
If it does, add icon.source with the URL to the card entry.
|
||||
|
||||
:param cards: List of card dictionaries (portfolio_cards)
|
||||
:param domains: Mapping of application_id to domain names
|
||||
:param web_protocol: Protocol to use (https or http)
|
||||
:return: New list of cards with icon.source set when available
|
||||
"""
|
||||
# Determine simpleicons service domain
|
||||
simpleicons_domain = domains.get('simpleicons')
|
||||
if isinstance(simpleicons_domain, list):
|
||||
simpleicons_domain = simpleicons_domain[0]
|
||||
if not simpleicons_domain:
|
||||
raise AnsibleFilterError("Domain for 'simpleicons' not found in domains mapping")
|
||||
base_url = f"{web_protocol}://{simpleicons_domain}"
|
||||
|
||||
enhanced = []
|
||||
for card in cards:
|
||||
title = card.get('title', '')
|
||||
if not title:
|
||||
enhanced.append(card)
|
||||
continue
|
||||
# Create slug from title
|
||||
slug = slugify(title)
|
||||
icon_url = f"{base_url}/{slug}.svg"
|
||||
try:
|
||||
resp = requests.head(icon_url, timeout=2)
|
||||
if resp.status_code == 200:
|
||||
card.setdefault('icon', {})['source'] = icon_url
|
||||
except requests.RequestException:
|
||||
# Ignore network errors and move on
|
||||
pass
|
||||
enhanced.append(card)
|
||||
return enhanced
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
"""Ansible filter plugin to add simpleicons source URLs to portfolio cards"""
|
||||
def filters(self):
|
||||
return {
|
||||
'add_simpleicon_source': add_simpleicon_source,
|
||||
}
|
@@ -24,3 +24,5 @@ galaxy_info:
|
||||
documentation: "https://github.com/kevinveenbirkenbach/portfolio#readme"
|
||||
logo:
|
||||
class: "fa-solid fa-briefcase"
|
||||
run_after:
|
||||
- docker-simpleicons
|
@@ -1,4 +1,5 @@
|
||||
---
|
||||
|
||||
- name: "include docker-compose role"
|
||||
include_role:
|
||||
name: docker-compose
|
||||
@@ -30,6 +31,13 @@
|
||||
portfolio_cards: "{{ lookup('docker_cards', 'roles') }}"
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: "Load images for applications feature simpleicons is enabled "
|
||||
set_fact:
|
||||
portfolio_cards: "{{ portfolio_cards | add_simpleicon_source(domains, web_protocol) }}"
|
||||
when:
|
||||
- (applications | is_feature_enabled('simpleicons',application_id))
|
||||
- run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Group docker cards
|
||||
set_fact:
|
||||
portfolio_menu_data: "{{ lookup('docker_cards_grouped', portfolio_cards, portfolio_menu_categories) }}"
|
||||
|
@@ -102,7 +102,7 @@ company:
|
||||
navigation:
|
||||
header:
|
||||
children:
|
||||
- link: accounts.publishingchannels.children
|
||||
- link: accounts.publishingchannels
|
||||
- name: Contact
|
||||
description: Get in touch with {{ 'us' if service_provider.type == 'legal' else 'me' }}
|
||||
icon:
|
||||
@@ -140,4 +140,10 @@ navigation:
|
||||
|
||||
{% endif %}
|
||||
|
||||
- name: Toggle Fullscreen
|
||||
description: Enter or exit fullscreen mode
|
||||
icon:
|
||||
class: fa-solid fa-expand-arrows-alt
|
||||
onclick: "toggleFullscreen()"
|
||||
|
||||
{% include 'footer_menu.yaml.j2' %}
|
@@ -2,6 +2,8 @@ features:
|
||||
matomo: true
|
||||
css: true
|
||||
portfolio_iframe: false
|
||||
simpleicons: true # Activate Brand Icons for your groups
|
||||
nasa_api_key: false # Set api key to use the Nasa Picture of the Day as Background
|
||||
csp:
|
||||
whitelist:
|
||||
script-src-elem:
|
||||
|
Reference in New Issue
Block a user