forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Static Website & deployment (facebookresearch#1544)
* Static website builder.
- Loading branch information
1 parent
1182d35
commit 679d7d4
Showing
20 changed files
with
2,211 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ joblib | |
nltk | ||
numpy | ||
pexpect | ||
py-gfm | ||
pyzmq | ||
regex | ||
requests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
all: clean | ||
python generate.py | ||
cd ../docs; make html | ||
pwd | ||
cp -a ../docs/build/html build/docs | ||
cp -a static build/ | ||
python postprocess_docs.py | ||
|
||
clean: | ||
rm -rf build/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is the code to build the parlai website. | ||
|
||
- `generate.py`: does the actual rendering | ||
- `static`: assets in this folder will be copied verbatim to parl.ai/static/ | ||
- `templates`: contains html templates for a variety of pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
""" | ||
Builds the ParlAI website. | ||
""" | ||
|
||
import os | ||
import git | ||
import markdown | ||
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') | ||
|
||
|
||
def ghmarkdown(source): | ||
return markdown.markdown( | ||
source, | ||
extensions=[PartialGithubFlavoredMarkdownExtension()] | ||
) | ||
|
||
|
||
def _read_file(filename): | ||
with open(filename) as f: | ||
return f.read() | ||
|
||
|
||
def _mkdirp(directory): | ||
"""Equivalent to mkdir -p""" | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
|
||
def _write_file(partial_filename, content): | ||
filename = os.path.join(OUT_DIR, partial_filename) | ||
|
||
_mkdirp(os.path.dirname(filename)) | ||
|
||
print("writing {} bytes to {}".format(len(content), filename)) | ||
with open(filename, 'w') as f: | ||
f.write(content) | ||
|
||
|
||
def wrap_base(content, title): | ||
template = _read_file(os.path.join(TEMPLATES, 'base.html')) | ||
template = template.replace('{{{CONTENT}}}', content) | ||
template = template.replace('{{{TITLE}}}', title) | ||
return template | ||
|
||
|
||
def make_errorpage(): | ||
content = _read_file(os.path.join(TEMPLATES, 'error.html')) | ||
html = wrap_base(content, "Error") | ||
_write_file('error.html', html) | ||
|
||
|
||
def make_aboutpage(): | ||
template = _read_file(os.path.join(TEMPLATES, 'about.html')) | ||
readme = _read_file(os.path.join(GIT_ROOT_LEVEL, 'README.md')) | ||
readme_html = ghmarkdown(readme) | ||
readme_html = readme_html.replace("docs/source/\\", "/docs/") | ||
content = template.replace('{{{CONTENT}}}', readme_html) | ||
html = wrap_base(content, "About | ParlAI") | ||
_write_file('about/index.html', html) | ||
|
||
|
||
def make_homepage(): | ||
template = _read_file(os.path.join(TEMPLATES, 'home.html')) | ||
news = _read_file(os.path.join(GIT_ROOT_LEVEL, 'NEWS.md')) | ||
news = news.replace('## News', '') | ||
news_html = ghmarkdown(news) | ||
content = template.replace('{{{CONTENT}}}', news_html) | ||
html = wrap_base(content, "ParlAI") | ||
_write_file('index.html', html) | ||
|
||
|
||
def make_projects_landing(): | ||
template = _read_file(os.path.join(TEMPLATES, 'project.html')) | ||
landing = _read_file(os.path.join(GIT_ROOT_LEVEL, 'projects/README.md')) | ||
landing = landing.replace( | ||
'This directory also contains subfolders for some of the projects which are ' | ||
'housed in the ParlAI repo, others are maintained via external websites. ' | ||
'Please also refer', | ||
'See the [ParlAI projects](https://github.com/facebookresearch/ParlAI/' | ||
'tree/master/projects) page on GitHub for more information. Refer' | ||
) | ||
landing_html = template.replace('{{{CONTENT}}}', ghmarkdown(landing)) | ||
html = wrap_base(landing_html, "Projects | ParlAI") | ||
_write_file('projects/index.html', html) | ||
|
||
|
||
def make_projects_individual(): | ||
template = _read_file(os.path.join(TEMPLATES, 'project.html')) | ||
projects_dir = os.path.join(GIT_ROOT_LEVEL, 'projects') | ||
possible_projects = os.listdir(projects_dir) | ||
projects = [ | ||
pp for pp in possible_projects | ||
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')) | ||
content_html = template.replace('{{{CONTENT}}}', ghmarkdown(content)) | ||
content_html = content_html.replace( | ||
'src="', | ||
'src="https://raw.githubusercontent.com/facebookresearch/' | ||
'ParlAI/master/projects/{}' | ||
.format(p + '/' if p else '') | ||
) | ||
title = p.title().replace("_", " ") | ||
html = wrap_base(content_html, title) | ||
_write_file(os.path.join('projects', p, 'index.html'), html) | ||
|
||
|
||
def main(): | ||
make_errorpage() | ||
make_homepage() | ||
make_aboutpage() | ||
make_projects_landing() | ||
make_projects_individual() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import os | ||
|
||
NEEDLE1 = '<a href="#" class="icon icon-home"> ParlAI' | ||
NEEDLE2 = '<a href="index.html" class="icon icon-home"> ParlAI' | ||
REPLACEMENT = """ | ||
<a href="/" style="float: left"> | ||
<img style="padding: 0px; background-color: #fff; width: 53px; height: 53px; margin-left: 70px;" src="/static/img/icon.png"> | ||
</a> | ||
<a href="/" style="color: #000; float: left; margin-top: 12px; font-size: 20px; font-weight: 600"> | ||
ParlAI | ||
</a> | ||
""" # noqa: E501 | ||
|
||
|
||
if __name__ == '__main__': | ||
for root, dirs, files in os.walk("build/docs/"): | ||
for file in files: | ||
if file.endswith(".html"): | ||
file_path = os.path.join(root, file) | ||
print("Postprocessing ", file_path) | ||
with open(file_path, 'r') as fin: | ||
content = fin.read() | ||
content = content.replace(NEEDLE1, REPLACEMENT) | ||
content = content.replace(NEEDLE2, REPLACEMENT) | ||
with open(file_path, 'w') as fout: | ||
fout.write(content) |
Oops, something went wrong.