Пример #1
0
    def generate(self):
        """Generate static site
        """
        logging.info('Loading drafts...')
        self.load_drafts()
        self.posts.sort(reverse=True)

        writers = [
            (writer.PostWriter, 'posts'),
            (writer.TagWriter, 'tags'),
            (writer.PageWriter, 'index'),
        ]

        if configs.rss:
            writers.append((writer.RssWriter, 'rss'))
        if configs.sitemap:
            writers.append((writer.SitemapWriter, 'sitemap'))
        if configs.archive:
            writers.append((writer.ArchiveWriter, 'archive'))

        logging.info('Rendering files...')
        for writer_class, desp in writers:
            logging.visiable(desp)
            w = writer_class(posts=self.posts, template=self.template)
            w.run()

        logging.info('%d posts', len(self.posts),
                prefix='🎉  ')
Пример #2
0
 def load_drafts(self):
     """Load all drafts
     """
     draft_dir = os.path.join(configs.pwd, configs.path.draft)
     for f in list_dir(draft_dir):
         logging.visiable('Reading {}'.format(f))
         self.parse_draft(f)
Пример #3
0
 def parse_dir(self, draft_dir):
     for f in list_dir(draft_dir):
         logging.visiable('Reading {}'.format(f))
         if (os.path.isdir(f)):
             self.parse_dir(f)
         else:
             self.parse_draft(f)
Пример #4
0
    def parse_draft(self, draft_file):
        """Parse draft file
        """
        draft = reader.read(draft_file)
        if not draft:
            logging.visiable('Failed', prefix='   ✗  ')
            return

        title = draft.get('title', None)
        slug = draft.get('slug', None)
        if not title or not slug:
            logging.visiable('✗ No title or slug', prefix='   ↳  ')
            return

        if not draft['meta'].get('publish', True):
            logging.visiable('✗ Don\'t publish', prefix='   ↳  ')
            return

        post = Post(title, slug, draft.get('content', None),
                draft.get('meta', None))

        self.posts.append(post)
        logging.visiable('✓ %s', post.title, prefix='   ↳  ')