Esempio n. 1
0
 def render(self, env, context, notes, categories, tags):
     per_page = self._config['per_page']
     page_total = (len(notes) + per_page - 1) / per_page
     context['url_for'] = self._config['url_for']
     context['categories'] = categories
     context['tags'] = tags
     # context['notes'] = notes
     output_dir = self._config['output_dir']
     root = self._config['root']
     # hardcode
     # don't leave this to user
     page = 'page'
     prev_text = '« Older'
     next_text = 'Newer »'
     template = env.get_template('index.html')
     for page_id in range(page_total):
         start = page_id * per_page
         context['notes'] = notes[start:start + per_page]
         context['pagination'] = paginate(page_id + 1, page_total, root,
                                          page, prev_text, next_text)
         html = template.render(context)
         if page_id == 0:
             target_path = os.path.join(output_dir,
                                        self._config['root'].strip('/'),
                                        'index.html')
         else:
             target_path = os.path.join(output_dir,
                                        self._config['root'].strip('/'),
                                        page, str(page_id + 1),
                                        'index.html')
         ensure_path(target_path)
         save_file(target_path, html)
Esempio n. 2
0
    def render(self, env, context):
        """
        Rendering the template note.html
        """

        # load markdown file
        self._raw_content = load_file(self.path)
        # parse frontmatter and strip it
        self._fm = self.parse_frontmatter_and_strip()
        self.article, self.toc = self.gen_md()
        self.set_link()
        context['title'] = self.title + ' | ' + context['title']
        context['note'] = self
        template = env.get_template('note.html')
        html = template.render(context)
        if self.category.name is not 'uncategorized':
            cate = self.category.name
        else:
            cate = ''
        target_path = os.path.join(self._config['output_dir'],
                                   self._config['root'].strip('/'),
                                   cate, self.name, 'index.html')
        # target_path = self.mk_path(self._config['output_dir'])
        ensure_path(target_path)

        save_file(target_path, html)
Esempio n. 3
0
    def render(self, env, context):
        """
        Rendering the template note.html
        """

        # load markdown file
        self._raw_content = load_file(self.path)
        # parse frontmatter and strip it
        self._fm = self.parse_frontmatter_and_strip()
        self.article, self.toc = self.gen_md()
        self.set_link()
        context['title'] = self.title + ' | ' + context['title']
        context['note'] = self
        template = env.get_template('note.html')
        html = template.render(context)
        if self.category.name is not 'uncategorized':
            cate = self.category.name
        else:
            cate = ''
        target_path = os.path.join(self._config['output_dir'],
                                   self._config['root'].strip('/'), cate,
                                   self.name, 'index.html')
        # target_path = self.mk_path(self._config['output_dir'])
        ensure_path(target_path)

        save_file(target_path, html)
Esempio n. 4
0
    def render(self, env, context):

        context['tag'] = self
        template = env.get_template('tag.html')
        html = template.render(context)

        target_path = os.path.join(self._config['output_dir'],
                                   self._config['root'].strip('/'),
                                   'tags', self.name, 'index.html')
        ensure_path(target_path)

        save_file(target_path, html)