コード例 #1
0
ファイル: core.py プロジェクト: elaOnMars/logya
    def write_index(self, url, collection):
        """Write an auto-generated index.html file."""

        check_doc_url = '/{}'.format(path.join(url, self.index_filename))
        # make sure there exists no document at the index url
        if check_doc_url not in self.docs:
            # Ugly fix for issue #32: delete description var. This is called
            # for every index, instead of once for all, because write_index is
            # called in serve mode. Also there may remain other vars causing
            # future problems.
            # Emptying the vars dict does not work either, because the index
            # key is set in build_index and needed.
            if 'description' in self.template.vars:
                del self.template.vars['description']

            title = self.index_title(url)

            self.template.vars['docs'] = collection.docs
            self.template.vars['title'] = title

            page = self.template.env.get_template(collection.template)
            content = page.render(self.template.vars)

            filename = path.target_file(self.dir_deploy, url)
            write(filename, content)

            # write directory RSS file
            self.write_rss(title, url, collection.docs)
コード例 #2
0
ファイル: core.py プロジェクト: thinkinpg/logya
    def write_index(self, url, collection):
        """Write an auto-generated index.html file."""

        check_doc_url = '/{}'.format(path.join(url, self.index_filename))
        # make sure there exists no document at the index url
        if check_doc_url not in self.docs:
            # Ugly fix for issue #32: delete description var. This is called
            # for every index, instead of once for all, because write_index is
            # called in serve mode. Also there may remain other vars causing
            # future problems.
            # Emptying the vars dict does not work either, because the index
            # key is set in build_index and needed.
            if 'description' in self.template.vars:
                del self.template.vars['description']

            title = self.index_title(url)

            self.template.vars['docs'] = collection.docs
            self.template.vars['title'] = title
            self.template.vars['canonical'] = '{:s}/{:s}/'.format(self.base_url, url)

            page = self.template.env.get_template(collection.template)
            content = page.render(self.template.vars)

            filename = path.target_file(self.dir_deploy, url)
            write(filename, content)

            # write directory RSS file
            self.write_rss(title, url, collection.docs)
コード例 #3
0
ファイル: core.py プロジェクト: thinkinpg/logya
    def write_rss(self, feed_title, url, docs):
        """Write RSS 2.0 XML file in target directory"""

        self.template.vars['url'] = self.base_url
        self.template.vars['title'] = feed_title
        self.template.vars['description'] = feed_title
        self.template.vars['last_build'] = datetime.datetime.now()
        self.template.vars['docs'] = docs

        content = self.pages['rss'].render(self.template.vars)

        filename = path.target_file(
            self.dir_deploy, path.join(url, 'rss.xml'))
        write(filename, content)
コード例 #4
0
ファイル: core.py プロジェクト: elaOnMars/logya
    def write_rss(self, feed_title, url, docs):
        """Write RSS 2.0 XML file in target directory"""

        self.template.vars['url'] = self.base_url
        self.template.vars['title'] = feed_title
        self.template.vars['description'] = feed_title
        self.template.vars['last_build'] = datetime.datetime.now()
        self.template.vars['docs'] = docs

        page = self.template.env.get_template(self.templates['rss'])
        content = page.render(self.template.vars)

        filename = path.target_file(
            self.dir_deploy, path.join(url, 'rss.xml'))
        write(filename, content)
コード例 #5
0
output_csv = os.path.join(L.dir_static, 'csv', args.output_name + '.csv')
df_final.to_csv(output_csv, index=False)

# Create content map
map_doc = {
    'title': 'World Map of Countries by ',
    'description': 'These choropleth maps show .',
    'created': now,
    'related': f'/info/{args.output_name}/',
    'scripts': [f'/compiled/map/{args.output_name}.js'],
    'template': 'map/world/choropleth.html',
    'image': f'/img/preview/{args.output_name}.png'
}
output_map = os.path.join(L.dir_content, 'map', 'world',
                          args.output_name + '.md')
write(output_map, encode_content(map_doc, ''))

# Create content info
info_doc = {
    'title': '',
    'description': 'Information on choropleth maps showing',
    'created': now,
    'related': f'/map/world/{args.output_name}/',
    'tags': ['d3', 'map', 'world', 'worldbank'],
    'template': 'page.html',
    'image': f'/img/preview/{args.output_name}.png'
}
output_info = os.path.join(L.dir_content, 'info', args.output_name + '.md')
write(output_info, encode_content(info_doc, ''))

JS = f"""
コード例 #6
0
            body.append(resources)

        doc = {
            'created': datetime.now(),
            'description': body[0].split('. ')[0] + '.',
            'groups': groups,
            'muscles': muscles,
            'template': 'exercise.html',
            'title': name,
            'variants': variants
        }
        # Files shall be saved as md files, so calling write_content directly
        # is not possible as it would save as html.
        filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(name)))
        if not os.path.exists(filename):
            write(filename, encode_content(doc, '\n\n'.join(body)))

        # Create stub files for variants
        for variant in variants:
            filename = target_file(logya.dir_content, '/exercise/{}.md'.format(slugify(variant)))
            if not os.path.exists(filename):
                ex_variants = list(set(variants).union(set([name])).difference(set([variant])))
                doc = {
                    'created': datetime.now(),
                    'description': '',
                    'groups': groups,
                    'muscles': muscles,
                    'template': 'exercise.html',
                    'title': variant,
                    'variants': ex_variants
                }
コード例 #7
0
        doc = {
            'created': datetime.now(),
            'description': body[0].split('. ')[0] + '.',
            'groups': groups,
            'muscles': muscles,
            'template': 'exercise.html',
            'title': name,
            'variants': variants
        }
        # Files shall be saved as md files, so calling write_content directly
        # is not possible as it would save as html.
        filename = target_file(logya.dir_content,
                               '/exercise/{}.md'.format(slugify(name)))
        if not os.path.exists(filename):
            write(filename, encode_content(doc, '\n\n'.join(body)))

        # Create stub files for variants
        for variant in variants:
            filename = target_file(logya.dir_content,
                                   '/exercise/{}.md'.format(slugify(variant)))
            if not os.path.exists(filename):
                ex_variants = list(
                    set(variants).union(set([name])).difference(set([variant
                                                                     ])))
                doc = {
                    'created': datetime.now(),
                    'description': '',
                    'groups': groups,
                    'muscles': muscles,
                    'template': 'exercise.html',
コード例 #8
0
ファイル: flatten_content.py プロジェクト: thinkinpg/logya
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This program flattens the content hierarchy of documents generated using the write_content function.
# It creates markdown versions from files named index.html in the directory content_new. New files get
# the name of their parent directory.
import os

from html2text import html2text

from logya.core import Logya
from logya.writer import encode_content, write

L = Logya()
L.init_env()
L.build_index()

for url, doc in L.docs.items():
    content_file = os.path.join(L.dir_content, url.strip('/'), 'index.html')
    if os.path.exists(content_file):
        body = html2text(doc['body'])

        # Cleanup
        del doc['body']
        if 'tags_links' in doc:
            del doc['tags_links']

        content = encode_content(doc, body)
        target_file = os.path.dirname(content_file) + '.md'

        write(target_file.replace('/content/', '/content_new/'), content)