diff --git a/glance-system/glance-kisfenyo.yaml b/glance-system/glance-kisfenyo.yaml index 4c3f7a1..f227ead 100644 --- a/glance-system/glance-kisfenyo.yaml +++ b/glance-system/glance-kisfenyo.yaml @@ -1964,58 +1964,34 @@ spec: fsGroup: 1000 initContainers: - name: build-bookmarks-index - image: python:3.12-alpine + image: mikefarah/yq:4 securityContext: - runAsUser: 0 - runAsGroup: 0 + runAsUser: 1000 + runAsGroup: 1000 allowPrivilegeEscalation: false command: ["/bin/sh", "-c"] args: - | - apk add --no-cache py3-yaml >/dev/null - python - <<'PY' - import json, os, yaml + set -e + mkdir -p /app/assets - cfg = yaml.safe_load(open('/config/glance.yml', 'r', encoding='utf-8')) - items = [] + yq -o=json ' + [ .pages[] as $p + | ($p.columns[]?.widgets[]? | select(.type == "bookmarks")) as $w + | $w.groups[]? as $g + | $g.links[]? + | select(.url != null and .url != "") + | { + title: ((.title // .url) | tostring), + url: (.url | tostring), + page: ($p.name // "" | tostring), + widget: ($w.title // "" | tostring), + group: ($g.title // "" | tostring) + } + ] | unique_by(.url) + ' /config/glance.yml > /app/assets/bookmarks.json - for page in cfg.get('pages', []): - page_name = page.get('name', '') - for col in page.get('columns', []): - for w in col.get('widgets', []): - if w.get('type') != 'bookmarks': - continue - widget_title = w.get('title', '') - for g in w.get('groups', []): - group_title = g.get('title', '') - for l in g.get('links', []): - title = (l.get('title') or '').strip() - url = (l.get('url') or '').strip() - if not url: - continue - items.append({ - "title": title or url, - "url": url, - "page": page_name, - "widget": widget_title, - "group": group_title, - }) - - # de-dupe by URL - seen = set() - out = [] - for it in items: - if it["url"] in seen: - continue - seen.add(it["url"]) - out.append(it) - - os.makedirs('/app/assets', exist_ok=True) - with open('/app/assets/bookmarks.json', 'w', encoding='utf-8') as f: - json.dump(out, f, ensure_ascii=False, indent=2) - - print(f"Wrote {len(out)} bookmarks -> /app/assets/bookmarks.json") - PY + echo "Bookmarks indexed: $(yq -r 'length' /app/assets/bookmarks.json)" volumeMounts: - name: config mountPath: /config