Skip to content

Commit

Permalink
saving icons to local repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Oct 2, 2023
1 parent 3003a0b commit 6fe80c8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from webassets.cache import MemoryCache

import repogen
from repogen.siteurl import siteurl

AUTHOR = 'webOS Homebrew Project'
SITENAME = 'webOS Homebrew Project'
SITEURL = ''
SITEURL = siteurl()

THEME = 'webosbrew'
theme_dir = Path(__file__, '..', 'theme').resolve()
Expand All @@ -28,11 +29,12 @@

PATH = 'content'

STATIC_PATHS = ['extra/CNAME', 'extra/favicon.ico', 'schemas']
STATIC_PATHS = ['extra/CNAME', 'extra/favicon.ico', 'schemas', 'apps/icons']
ARTICLE_EXCLUDES = ['api']
PAGE_PATHS = ['pages', 'apps', '../packages']

EXTRA_PATH_METADATA = {
'apps/icons': {'path': 'apps/icons/'},
'extra/CNAME': {'path': 'CNAME'},
'extra/favicon.ico': {'path': 'favicon.ico'},
}
Expand Down
3 changes: 3 additions & 0 deletions repogen/apidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

from repogen import pkg_info
from repogen.common import ITEMS_PER_PAGE, ensure_open
from repogen.icons import obtain_icon
from repogen.pkg_info import PackageInfo
from repogen.siteurl import siteurl

MANIFEST_KEYS = ('id', 'title', 'iconUri', 'manifestUrl', 'manifest', 'manifestUrlBeta', 'manifestBeta', 'pool')

Expand Down Expand Up @@ -40,6 +42,7 @@ def package_item(p_info: PackageInfo, in_apps_dir: bool):
package['fullDescriptionUrl'] = f'{p_info["id"]}/full_description.html'
else:
package['fullDescriptionUrl'] = f'apps/{p_info["id"]}/full_description.html'
package['iconUri'] = obtain_icon(package['id'], p_info["iconUri"], siteurl())
return package

packages_length = len(packages)
Expand Down
25 changes: 25 additions & 0 deletions repogen/icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pathlib import Path

import requests

_approot = Path(__file__).parent.parent

assert _approot.samefile(os.getcwd())

_iconspath = _approot.joinpath('content', 'apps', 'icons')

_iconspath.mkdir(parents=True, exist_ok=True)


def obtain_icon(pkg_id: str, uri: str, siteurl: str) -> str:
resp = requests.get(uri, allow_redirects=True)
extension = uri[uri.rfind('.') + 1:]
icon_name = f'{pkg_id}.{extension}'
icon_path = _iconspath.joinpath(icon_name)
out_uri = f'{siteurl.removesuffix("/")}/apps/icons/{icon_name}'
if icon_path.exists():
return out_uri
with icon_path.open('wb') as icon_f:
icon_f.write(resp.content)
return out_uri
2 changes: 2 additions & 0 deletions repogen/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pelican.themes.webosbrew import pagination_data

from repogen import funding, apidata, pkg_info
from repogen.icons import obtain_icon

log = logging.getLogger(__name__)

Expand All @@ -25,6 +26,7 @@ def __init__(self, *args, **kwargs):

def read(self, filename: str):
info = pkg_info.from_package_info_file(Path(filename), offline='CI' not in os.environ)
info['iconUri'] = obtain_icon(info['id'], info['iconUri'], self.settings['SITEURL'])
metadata = {
'title': info['title'],
'override_save_as': f'apps/{info["id"]}.html',
Expand Down
8 changes: 8 additions & 0 deletions repogen/siteurl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path


def siteurl() -> str:
cname_file = Path(__file__, '..', '..', 'content', 'extra', 'CNAME')
if not cname_file.exists():
return ''
return f'https://{cname_file.read_text().strip()}'

0 comments on commit 6fe80c8

Please sign in to comment.