Skip to content

Commit

Permalink
Copy specific file extensions to the website. (facebookresearch#2594)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenroller authored Apr 28, 2020
1 parent ea00f8f commit ad10bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion website/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import os
import git
import markdown
import shutil
from mdx_gfm import PartialGithubFlavoredMarkdownExtension

GIT_ROOT_LEVEL = git.Git().rev_parse('--show-toplevel')
WEBSITE_ROOT = os.path.join(GIT_ROOT_LEVEL, 'website')
TEMPLATES = os.path.join(WEBSITE_ROOT, 'templates')
OUT_DIR = os.path.join(WEBSITE_ROOT, 'build')

STATIC_FILE_EXTS = {'.css', '.jpg', '.jpeg', '.png', '.json', '.jsonl', '.html', '.md'}


def ghmarkdown(source):
return markdown.markdown(
Expand Down Expand Up @@ -110,7 +113,8 @@ def make_projects_individual():
if os.path.exists(os.path.join(projects_dir, pp, 'README.md'))
]
for p in projects:
content = _read_file(os.path.join(projects_dir, p, 'README.md'))
project_dir = os.path.join(projects_dir, p)
content = _read_file(os.path.join(project_dir, 'README.md'))
content_html = template.replace('{{{CONTENT}}}', ghmarkdown(content))
content_html = content_html.replace(
'src="',
Expand All @@ -121,6 +125,19 @@ def make_projects_individual():
html = wrap_base(content_html, title)
_write_file(os.path.join('projects', p, 'index.html'), html)

# if there are any static files in the project folder, copy them over
# to the website
files = os.listdir(project_dir)
for fn in files:
_, ext = os.path.splitext(fn.lower())
if ext in STATIC_FILE_EXTS:
src = os.path.join(project_dir, fn)
nice_src = os.path.relpath(src, GIT_ROOT_LEVEL)
dest = os.path.join(OUT_DIR, 'projects', p, fn)
nice_dest = os.path.relpath(dest, GIT_ROOT_LEVEL)
print(f"Copy {nice_src} -> {nice_dest}")
shutil.copyfile(src, dest)


def main():
make_errorpage()
Expand Down
6 changes: 3 additions & 3 deletions website/postprocess_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import os

NEEDLE3 = '<title>ParlAI Documentation &mdash; ParlAI documentation</title>'
NEEDLE3 = '&mdash; ParlAI documentation</title>'
REPLACEMENT3 = """
<title>ParlAI Documentation &mdash; ParlAI documentation</title>
&mdash; ParlAI Documentation</title>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-32x32.png" sizes="32x32"/>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-16x16.png" sizes="16x16"/>
<link rel="shortcut icon" type="image/png" href="/static/img/favicon-96x96.png" sizes="96x96"/>
""" # noqa: E501
""".strip() # noqa: E501


if __name__ == '__main__':
Expand Down

0 comments on commit ad10bce

Please sign in to comment.