Exemple #1
0
    def _parse(self, container):
        for f in container.path:
            Timer.start()

            item = Item(f.path)

            try:
                frontmatter, bodymatter = re.search(
                    r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content,
                    re.M | re.S).groups()
                frontmatter = Config(frontmatter)
            except AttributeError:
                raise ContentException('Invalid frontmatter.',
                                       'src: {0}'.format(f.path),
                                       'frontmatter must not be empty')
            except ConfigException:
                raise ConfigException('Invalid frontmatter.',
                                      'src: {0}'.format(f.path),
                                      'fontmatter contains invalid YAML')

            if 'layout' not in frontmatter:
                raise ContentException('Invalid frontmatter.',
                                       'src: {0}'.format(f.path),
                                       'layout must be set')

            parser = self._get_parser(
                f,
                frontmatter.get('parser', container.config.get('parser',
                                                               None)))

            slug, date = self._parse_filename(f)
            content = parser.parse(
                self._writer.from_string(bodymatter, frontmatter))

            item['content'] = content
            item['date'] = date.strftime(
                self.site['date_format']).decode('utf-8')
            item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content,
                                        re.M | re.S).group(1)
            item['tags'] = []
            item['timestamp'] = timegm(date.utctimetuple())

            item.update(frontmatter)

            item['url'] = self._get_content_url(container.config['url'], slug,
                                                date, frontmatter)

            container.add(item)

            logger.debug('..  (%.3fs) %s', Timer.stop(),
                         f.path.replace(self.src.path, ''))

        container.sort()
        container.tag()
        container.archive()

        return container
Exemple #2
0
    def _parse_item(self, config, f, simple = False):
        Timer.start()

        item = Item(f.path)

        try:
            frontmatter, bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content, re.M | re.S).groups()
            frontmatter = Config(frontmatter)
        except AttributeError:
            raise ContentException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'frontmatter must not be empty')
        except ConfigException:
            raise ConfigException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'fontmatter contains invalid YAML')

        if 'layout' not in frontmatter:
            raise ContentException('Invalid frontmatter.',
                'src: {0}'.format(f.path),
                'layout must be set')

        parser = self._get_parser(f, frontmatter.get('parser', config.get('parser', None)))

        text, date = self._parse_filename(f)

        frontmatter.pop('url', None)
        frontmatter['slug'] = text

        result = parser.parse(self._writer.from_string(bodymatter, frontmatter))

        content, toc = result if isinstance(result, tuple) else (result, None)

        item['content'] = content
        item['date'] = date.strftime(self.site['date_format']).decode('utf-8')
        item['timestamp'] = timegm(date.utctimetuple())

        if toc is not None:
            item['toc'] = toc

        if simple:
            item['url'] = Url.from_path(f.root.path.replace(self.src.path, ''), text)
        else:
            item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
            item['tags'] = []
            item['url'] = Url.from_format(config['url'], text, date, frontmatter)

        item.update(frontmatter)

        logger.debug('..  (%.3fs) %s', Timer.stop(), f.path.replace(self.src.path, ''))

        return item
Exemple #3
0
 def _parse(self, container):
     for f in container.path:
         Timer.start()
         
         item = Item(f.path)
         
         try:
             frontmatter, bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content, re.M | re.S).groups()
             frontmatter = Config(frontmatter)
         except AttributeError:
             raise ContentException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'frontmatter must not be empty')
         except ConfigException:
             raise ConfigException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'fontmatter contains invalid YAML')
         
         if 'layout' not in frontmatter:
             raise ContentException('Invalid frontmatter.',
                 'src: {0}'.format(f.path),
                 'layout must be set')
         
         parser = self._get_parser(f, frontmatter.get('parser', container.config.get('parser', None)))
         
         slug, date = self._parse_filename(f)
         content = parser.parse(self._writer.from_string(bodymatter, frontmatter))
         
         item['content'] = content
         item['date'] = date.strftime(self.site['date_format']).decode('utf-8')
         item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
         item['tags'] = []
         item['timestamp'] = timegm(date.utctimetuple())
         
         item.update(frontmatter)
         
         item['url'] = self._get_content_url(container.config['url'], slug, date, frontmatter)
         
         container.add(item)
         
         logger.debug('..  (%.3fs) %s', Timer.stop(), f.path.replace(self.src.path, ''))
     
     container.sort()
     container.tag()
     container.archive()
     
     return container
Exemple #4
0
 def _parse_item(self, config, f, simple = False):
     Timer.start()
     
     item = Item(f.path)
     
     try:
         frontmatter, bodymatter = re.search(r'\A---\s+^(.+?)$\s+---\s*(.*)\Z', f.content, re.M | re.S).groups()
         frontmatter = Config(frontmatter)
     except AttributeError:
         raise ContentException('Invalid frontmatter.',
             'src: {0}'.format(f.path),
             'frontmatter must not be empty')
     except ConfigException:
         raise ConfigException('Invalid frontmatter.',
             'src: {0}'.format(f.path),
             'fontmatter contains invalid YAML')
     
     if 'layout' not in frontmatter:
         raise ContentException('Invalid frontmatter.',
             'src: {0}'.format(f.path),
             'layout must be set')
     
     frontmatter.pop('url', None)
     
     parser = self._get_parser(f, frontmatter.get('parser', config.get('parser', None)))
     
     text, date = self._parse_filename(f)
     content = parser.parse(self._writer.from_string(bodymatter, frontmatter))
     
     item['content'] = content
     item['date'] = date.strftime(self.site['date_format'])
     item['timestamp'] = timegm(date.utctimetuple())
     
     if simple:
         item['url'] = Url.from_path(f.root.path.replace(self.src.path, ''), text)
     else:
         item['excerpt'] = re.search(r'\A.*?(?:<p>(.+?)</p>)?', content, re.M | re.S).group(1)
         item['tags'] = []
         item['url'] = Url.from_format(config['url'], text, date, frontmatter)
     
     item.update(frontmatter)
     
     logger.debug('..  (%.3fs) %s', Timer.stop(), f.path.replace(self.src.path, ''))
     
     return item