Exemple #1
0
    def __init__(self, path, conf):

        self.filename = path
        self.tzinfo = conf.get('tzinfo', None)

        with io.open(path, 'r', encoding='utf-8', errors='replace') as fp:

            peak = lchop(fp.read(512), BOM_UTF8)
            fp.seek(0)

            if peak.startswith('---\n'):
                i, meta = yamlstyle(fp)
            elif re.match('^\w+\n=+', peak):
                i, meta = reststyle(fp)
            elif peak.startswith('% '):
                i, meta = pandocstyle(fp)
            else:
                i, meta = markdownstyle(fp)

        meta['title'] = unicode(meta['title'])  # YAML can convert 42 to an int

        jekyll = r'(?:(.+?)/)?(\d{4}-\d{2}-\d{2})-(.+)'
        m = re.match('^' + conf['content_dir'] + jekyll + '$', splitext(path)[0])

        if m:
            meta.setdefault('date', m.group(2))
            meta.setdefault('slug', m.group(3))

            if m.group(1) is not None:
                meta['cats'] = m.group(1).split('/')

        self.offset = i
        Reader.__init__(self, conf, meta)
Exemple #2
0
    def __init__(self, path, conf):

        self.filename = path
        self.tzinfo = conf.get('tzinfo', None)
        self.defaultcopywildcard = conf.get('copy_wildcard', '_[0-9]*.*')

        with io.open(path, 'r', encoding='utf-8', errors='replace') as fp:

            peak = lchop(fp.read(512), BOM_UTF8)
            fp.seek(0)

            if peak.startswith('---\n'):
                i, meta = yamlstyle(fp)
            elif isrest(peak):
                i, meta = reststyle(fp)
            elif peak.startswith('% '):
                i, meta = pandocstyle(fp)
            else:
                i, meta = markdownstyle(fp)

        meta['title'] = str(meta['title'])  # YAML can convert 42 to an int
        meta['category'] = lchop(dirname(path) + '/',
                                 conf['content_dir']).split('/')

        jekyll = r'(?:(.+?)/)?(\d{4}-\d{2}-\d{2})-(.+)'
        m = re.match('^' + conf['content_dir'] + jekyll + '$',
                     splitext(path)[0])

        if m:
            meta.setdefault('date', m.group(2))
            meta.setdefault('slug', m.group(3))

            if m.group(1) is not None:
                meta['category'] = m.group(1).split('/')

        self.offset = i
        Reader.__init__(self, conf, meta)

        path, ext = os.path.splitext(path)
        self.path = lchop(path, conf['content_dir'])
        self.extension = ext[1:]
Exemple #3
0
    def __init__(self, path, conf):

        self.filename = path
        self.tzinfo = conf.get('tzinfo', None)
        self.defaultcopywildcard = conf.get('copy_wildcard', '_[0-9]*.*')

        with io.open(path, 'r', encoding='utf-8', errors='replace') as fp:

            peak = lchop(fp.read(512), BOM_UTF8)
            fp.seek(0)

            if peak.startswith('---\n'):
                i, meta = yamlstyle(fp)
            elif isrest(peak):
                i, meta = reststyle(fp)
            elif peak.startswith('% '):
                i, meta = pandocstyle(fp)
            else:
                i, meta = markdownstyle(fp)

        meta['title'] = str(meta['title'])  # YAML can convert 42 to an int
        meta['category'] = lchop(dirname(path) + '/', conf['content_dir']).split('/')

        jekyll = r'(?:(.+?)/)?(\d{4}-\d{2}-\d{2})-(.+)'
        m = re.match('^' + conf['content_dir'] + jekyll + '$', splitext(path)[0])

        if m:
            meta.setdefault('date', m.group(2))
            meta.setdefault('slug', m.group(3))

            if m.group(1) is not None:
                meta['category'] = m.group(1).split('/')

        self.offset = i
        Reader.__init__(self, conf, meta)

        path, ext = os.path.splitext(path)
        self.path = lchop(path, conf['content_dir'])
        self.extension = ext[1:]
Exemple #4
0
 def fetch(self, ns):
     return Configuration((lchop(k, ns), v)
         for k, v in self.iteritems() if k.startswith(ns))
Exemple #5
0
 def source(self):
     """Returns the actual, unmodified content."""
     with io.open(self.filename, 'r', encoding='utf-8') as f:
         return lchop(''.join(f.readlines()[self.offset:]).strip('\n'), BOM_UTF8)
Exemple #6
0
 def source(self):
     """Returns the actual, unmodified content."""
     with io.open(self.filename, 'r', encoding='utf-8') as f:
         return lchop(''.join(f.readlines()[self.offset:]).strip('\n'),
                      BOM_UTF8)
Exemple #7
0
 def fetch(self, ns):
     return Configuration(
         (lchop(k, ns), v) for k, v in iteritems(self) if k.startswith(ns))