commit d17a987aa3acb9ce100129a37c3714a743a78a59 Author: max/sooulix Date: Thu Aug 15 00:39:06 2024 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbfa7d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.pyc diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..7b2ca9b --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .jsonresume_reader import * diff --git a/jsonresume_reader.py b/jsonresume_reader.py new file mode 100644 index 0000000..c6e6ffd --- /dev/null +++ b/jsonresume_reader.py @@ -0,0 +1,68 @@ +""" +JSONResume Reader +========== + +Version 0 + +""" +import os +import json +import locale +import logging +import subprocess +from datetime import date +from pelican import readers +from pelican import signals + + +class JSONResumeReader(readers.RstReader): + enabled = True + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def read(self, filename): + content, metadata = super().read(filename) + if not('jsonresume' in metadata and os.path.isfile(metadata['jsonresume'])): + raise Exception('please give a jsonresume metadata field for this type') + if not(f'jsonresume_{self._language_code}' in metadata and os.path.isfile(metadata[f'jsonresume_{self._language_code}'])): + raise Exception('please give a jsonresume_languagecode metadata field for this type') + + metadata['resume'] = json.load(open(metadata['jsonresume'])) + metadata['language'] = json.load(open(metadata[f'jsonresume_{self._language_code}'])) + metadata['locale'] = self.settings.get('LOCALE', [self.settings.get('DEFAULT_LOCALE', None)]) + countryname = lambda code: 'langue' + + def setlocale(fct): + def wrapped(d): + set_locale = self.settings.get('LOCALE', [self.settings.get('DEFAULT_LOCALE', None)]) + + if set_locale is not None and len(set_locale) > 0: + locale.setlocale(locale.LC_TIME, set_locale[0]) + + return fct(d) + + return wrapped + + + @setlocale + def format_date_short(d): + return date.fromisoformat(d).strftime('%B %Y').capitalize() + + format_date_full = lambda d: date.fromisoformat(d).strftime('%d %B %Y').capitalize() + isinfinite = lambda d: date.fromisoformat(d).isoformat() == '2999-01-01' + metadata['utils'] = { + 'get_country_name': countryname, + 'format_date_short': format_date_short, + 'format_date_full': format_date_full, + 'isinfinite': isinfinite + } + return content, metadata + + +def add_reader(readers): + readers.reader_classes['jsonresume'] = JSONResumeReader + + +def register(): + signals.readers_init.connect(add_reader)