""" 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') metadata['resume'] = json.load(open(metadata['jsonresume'])) 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() @setlocale def format_date_year(d): return date.fromisoformat(d).strftime('%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, 'format_date_year': format_date_year, 'isinfinite': isinfinite } return content, metadata def add_reader(readers): readers.reader_classes['jsonresume'] = JSONResumeReader def register(): signals.readers_init.connect(add_reader)