From d17a987aa3acb9ce100129a37c3714a743a78a59 Mon Sep 17 00:00:00 2001 From: max/sooulix Date: Thu, 15 Aug 2024 00:39:06 +0200 Subject: [PATCH] initial commit --- .gitignore | 1 + __init__.py | 1 + jsonresume_reader.py | 68 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 jsonresume_reader.py 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)