예제 #1
0
def get_chapter_docs(chapter_id):
    doc_files = collect.readfiles(
        '%s/%s' % (settings.DOCS_ROOT, chapter_id),
        'md'
    )

    docs = []
    for id in sorted(doc_files.keys()):
        doc = {
            'id': id,
            'chapter': chapter_id,
        }

        # Extract modification timestamp from git log
        pipe = subprocess.Popen([
            "git", "log", "-1", "--format=%ai", "%s/%s.md" % (chapter_id, id)
        ], stdout=subprocess.PIPE, cwd=settings.DOCS_ROOT)

        # FIXME: handle time zone?
        parts = pipe.stdout.read().decode('utf-8').split(" ")
        doc['updated'] = datetime.datetime.strptime(
            parts[0] + " " + parts[1], "%Y-%m-%d %X"
        )

        # Googlebot doesn't like webpage URLs ending with .js
        if id.endswith('.js'):
            doc['id'] = id.replace('.js', '-js')
            doc['is_jsdoc'] = True

        markdown = doc_files[id]
        # Optional YAML front matter
        if markdown.startswith('---'):
            conf, markdown = markdown[3:].split("\n---\n")
            doc.update(yaml.load(conf))
            markdown = markdown[1:]

        if 'title' not in doc:
            doc['title'] = re.match('(.*)', markdown).group(0)
        if 'description' not in doc:
            match = re.search(r'\n(.+?\.)\s', markdown)
            if match:
                desc = match.group(1)
                desc = desc.replace('[', '')
                desc = desc.replace(']', '')
                desc = desc.replace('*', '')
                desc = desc.replace('`', '')
                doc['description'] = desc
        if 'image' not in doc:
            match = re.search(r"wq.io/(.+?)\.png", markdown)
            if match:
                doc['image'] = "/%s.png" % match.group(1)

        doc['markdown'] = markdown
        doc['interactive'] = "data-interactive" in markdown

        docs.append(doc)

    return docs
예제 #2
0
        },
    }
}

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

# wq: Configure paths for default project layout
STATIC_ROOT = os.path.join(BASE_DIR, 'htdocs', 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
DOCS_ROOT = os.path.join(BASE_DIR, 'wq', 'docs')
VERSION_TXT = os.path.join(BASE_DIR, 'version.txt')
MEDIA_URL = '/media/'
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

# wq: Import local settings
try:
    from .local_settings import *
except ImportError:
    pass

from wq.app.build import collect
CONF = collect.readfiles(os.path.join(BASE_DIR, 'conf'), 'yaml', 'yml')