Esempio n. 1
0
# -*- coding: utf-8 -*-
# Run this script from your Logya site directory, e. g.:
# python scripts/site_index.py
import io
import os
import json

from logya.core import Logya
from logya.encoder import JSONEncoder


logya = Logya()
logya.init_env()
logya.build_index()

site_index = {}
for url, doc in logya.docs.items():
    del doc['body']
    site_index[url] = doc

index_file = os.path.join(logya.dir_static, 'site_index.json')
with io.open(index_file, 'w', encoding='utf-8') as f:
    json.dump(site_index, f, cls=JSONEncoder)
Esempio n. 2
0
# -*- coding: utf-8 -*-
# Run this script from your Logya site directory, e. g.:
# python scripts/site_index.py
import io
import os
import json

from logya.core import Logya
from logya.encoder import JSONEncoder

logya = Logya()
logya.init_env()
logya.build_index()

site_index = {}
for url, doc in logya.docs.items():
    del doc['body']
    site_index[url] = doc

index_file = os.path.join(logya.dir_static, 'site_index.json')
with io.open(index_file, 'w', encoding='utf-8') as f:
    json.dump(site_index, f, cls=JSONEncoder)
Esempio n. 3
0
#!/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)