Ejemplo n.º 1
0
def process_toc_entry(entry, path, idx):
    if isinstance(entry, list):
        for e in entry:
            idx = process_toc_entry(e, path, idx)
    elif isinstance(entry, dict):
        for key, value in entry.items():
            next_path = path + [make_key(key)]
            index_md_idx = idx
            idx += 1

            if isinstance(value, list):
                for v in value:
                    process_toc_entry(v, next_path, idx)
                    idx += 1
            else:
                process_md_file(key, idx, value, path)
                idx += 1

            index_md_path = os.path.join(docs_dir, '/'.join(next_path),
                                         'index.md')
            if os.path.exists(os.path.dirname(index_md_path)):
                index_meta, index_content = util.read_md_file(index_md_path)
                if not index_meta.get('toc_folder_title'):
                    index_meta['toc_folder_title'] = key
                index_meta['toc_priority'] = index_md_idx
                util.write_md_file(index_md_path, index_meta, index_content)
                subprocess.check_call(f'git add {index_md_path}', shell=True)
    return idx
Ejemplo n.º 2
0
def process_md_file(title, idx, original_path, proper_path):
    proper_md_path = '/'.join(proper_path + [original_path.rsplit('/', 1)[-1]])
    if proper_md_path == 'introduction/index.md':
        proper_md_path = 'index.md'
    print(locals())
    if original_path != proper_md_path:
        redirects[original_path] = proper_md_path
    original_path = os.path.join(docs_dir, original_path)
    proper_md_path = os.path.join(docs_dir, proper_md_path)
    if os.path.exists(original_path):
        meta, content = util.read_md_file(original_path)
    else:
        meta, content = util.read_md_file(proper_md_path)
    meta['toc_title'] = title
    meta['toc_priority'] = idx
    if title == 'hidden':
        meta['toc_hidden'] = True

    for src, dst in redirects.items():
        content = content.replace('(' + src, '(' + dst)
        content = content.replace('../' + src, '../' + dst)

    util.write_md_file(proper_md_path, meta, content)
    if original_path != proper_md_path:
        subprocess.check_call(f'git add {proper_md_path}', shell=True)
        if os.path.exists(original_path):
            subprocess.check_call(f'rm {original_path}', shell=True)
Ejemplo n.º 3
0
def sync_translation():
    init_redirects()
    for src, dst in redirects.items():
        en_src = os.path.join(en_dir, src)
        lang_src = os.path.join(docs_dir, src)
        lang_dst = os.path.join(docs_dir, dst)
        if os.path.exists(lang_src):
            if os.path.islink(lang_src):
                pass
            else:
                en_meta, en_content = util.read_md_file(en_src)
                lang_meta, lang_content = util.read_md_file(lang_src)
                en_meta.update(lang_meta)

                for src_link, dst_link in redirects.items():
                    lang_content = lang_content.replace('(' + src_link, '(' + dst)
                    lang_content = lang_content.replace('../' + src_link, '../' + dst)
                    
                util.write_md_file(lang_dst, en_meta, lang_content)
                subprocess.check_call(f'git add {lang_dst}', shell=True)
                subprocess.check_call(f'rm {lang_src}', shell=True)
Ejemplo n.º 4
0
#!/usr/bin/env python3
import os
import subprocess
import sys

import util

if __name__ == '__main__':
    path = sys.argv[1]
    content_path = f'{path}.content'
    meta_path = f'{path}.meta'
    meta, content = util.read_md_file(path)

    target_language = os.getenv('TARGET_LANGUAGE')
    if target_language is not None and target_language != 'en':
        rev = subprocess.check_output('git rev-parse HEAD',
                                      shell=True).decode('utf-8').strip()
        meta['machine_translated'] = True
        meta['machine_translated_rev'] = rev

    with open(content_path, 'w') as f:
        print(content, file=f)

    util.write_md_file(meta_path, meta, '')
Ejemplo n.º 5
0
#!/usr/bin/env python3
import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import convert_toc
import util

if __name__ == '__main__':
    path = sys.argv[1][2:]
    convert_toc.init_redirects()
    try:
        path = convert_toc.redirects[path]
    except KeyError:
        pass
    meta, content = util.read_md_file(path)
    if 'machine_translated' in meta:
        del meta['machine_translated']
    if 'machine_translated_rev' in meta:
        del meta['machine_translated_rev']
    util.write_md_file(path, meta, content)