Skip to content

Commit

Permalink
Merge pull request #766 from avaris/fix-broken-theme-previews
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer authored Dec 12, 2023
2 parents d01c114 + 9e04d32 commit 8909649
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-preview-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
with:
path: ~/.cache/ms-playwright/
key: ${{ runner.os }}-browsers
- name: Install pelican and shot-scraper
run: pip install pelican[markdown] shot-scraper
- name: Install pelican, plugins and shot-scraper
run: pip install pelican[markdown] pelican-webassets cssmin shot-scraper
- name: Setup shot-scraper
run: shot-scraper install
- name: Generate output
Expand Down
46 changes: 44 additions & 2 deletions build-theme-previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@
)
logger = logging.getLogger()


PELICANCONF_PATCH = """
class i18n(object):
# looks for translations in
# {LOCALE_DIR}/{LANGUAGE}/LC_MESSAGES/{DOMAIN}.mo
# if not present, falls back to default
DOMAIN = 'messages'
LOCALE_DIR = 'does-not-matter/translations'
LANGUAGES = ['de']
NEWSTYLE = True
__name__ = 'i18n'
def register(self):
from pelican import signals
signals.generator_init.connect(self.install_translator)
def install_translator(self, generator):
import gettext
try:
translator = gettext.translation(
self.DOMAIN,
self.LOCALE_DIR,
self.LANGUAGES)
except (OSError, IOError):
translator = gettext.NullTranslations()
generator.env.install_gettext_translations(translator, self.NEWSTYLE)
JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']}
PLUGINS = [i18n(), 'webassets']
"""


HTML_HEADER = """\
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -134,6 +170,11 @@ def build_theme_previews(theme_root, samples_root, output_root, screenshot_root)
success = {}
screenshot_processes = []

modified_settings_path = os.path.join(output_root, "pelicanconf.py")
with open(os.path.join(samples_root, 'pelican.conf.py')) as infile:
with open(modified_settings_path, 'w') as outfile:
outfile.write(infile.read() + PELICANCONF_PATCH)

for theme in sorted(themes, key=lambda x: x.lower()):
theme_path = os.path.join(theme_root, theme)
if os.path.exists(os.path.join(theme_path, theme, "templates")):
Expand All @@ -144,13 +185,13 @@ def build_theme_previews(theme_root, samples_root, output_root, screenshot_root)
process = subprocess.run([
"pelican",
os.path.join(samples_root, "content"),
"--settings", os.path.join(samples_root, "pelican.conf.py"),
"--settings", modified_settings_path,
"--extra-settings", f"SITENAME=\"{theme} preview\"",
"--relative-urls",
"--theme-path", theme_path,
"--output", output_path,
"--ignore-cache",
"--delete-output-directory"
"--delete-output-directory",
],
check=True, capture_output=True, universal_newlines=True)
except subprocess.CalledProcessError as exc:
Expand All @@ -172,6 +213,7 @@ def build_theme_previews(theme_root, samples_root, output_root, screenshot_root)
for process in screenshot_processes:
process.wait()
server.terminate()
os.remove(modified_settings_path)
return success, fail


Expand Down

0 comments on commit 8909649

Please sign in to comment.