Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _layouts/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if page.layout == "manual" and page.language -%}
{%- if page.language -%}
<!DOCTYPE html>
<html lang="{{ page.language }}">
{%- else -%}
Expand Down
70 changes: 66 additions & 4 deletions _layouts/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
<div style="display: none;" data-pagefind-meta="section">Tutorials</div>
{% include learnnav.html showmenu=true %}

{%- assign page_language = page.language | default: "en" -%}
{%- assign language = site.data.languageindex | where: "language", page_language | first -%}
{%- assign github_link = page.github | default: "https://github.com/defold/doc" -%}
{%- for tutorial in site.data.learnindex.navigation.tutorials -%}
{%- if tutorial.path contains "/tutorials/" -%}
{%- assign tutorial_path = tutorial.path | append: "/" -%}
{%- assign tutorial_path_size = tutorial_path | size -%}
{%- assign page_url_size = page.url | size -%}
{%- assign start_index = page_url_size | minus: tutorial_path_size -%}
{%- assign result = page.url | slice: start_index, tutorial_path_size -%}
{%- if result == tutorial_path -%}
{%- assign current_tutorial = tutorial -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}

<div class="section lightest dark:dark">
<div class="container">
<div class="row">
Expand All @@ -18,30 +34,76 @@
{%- assign checked = "checked" -%}
{%- endif -%}
<li style="padding-left: 2rem;">
<a href="{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }}</a>
{%- if tutorial.path contains "/tutorials/" -%}
{%- if page_language == "en" -%}
<a href="{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }}</a>
{%- elsif tutorial.languages contains page_language -%}
<a href="/{{ language.urlprefix }}{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }}</a>
{%- else -%}
<a href="{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }} (English)</a>
{%- endif -%}
{%- else -%}
<a href="{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }}</a>
{%- endif -%}
</li>
{% endfor %}
</ul>
</div>
<div class="dropdownmenu">
<select class="dropdownmenu" onchange="location = this.value;">
{% for tutorial in site.data.learnindex.navigation.tutorials %}
<option value="{{ tutorial.path }}" {% if page.url contains tutorial.path %}selected{% endif %}> - {{ tutorial.name }}</option>
{%- if tutorial.path contains "/tutorials/" -%}
{%- if page_language == "en" -%}
<option value="{{ tutorial.path }}" {% if page.url contains tutorial.path %}selected{% endif %}> - {{ tutorial.name }}</option>
{%- elsif tutorial.languages contains page_language -%}
<option value="/{{ language.urlprefix }}{{ tutorial.path }}" {% if page.url contains tutorial.path %}selected{% endif %}> - {{ tutorial.name }}</option>
{%- else -%}
<option value="{{ tutorial.path }}" {% if page.url contains tutorial.path %}selected{% endif %}> - {{ tutorial.name }} (English)</option>
{%- endif -%}
{%- else -%}
<option value="{{ tutorial.path }}" {% if page.url contains tutorial.path %}selected{% endif %}> - {{ tutorial.name }}</option>
{%- endif -%}
{% endfor %}
</select>
</div>
</div>
<div class="columns eight tutorial" data-pagefind-body>
<div class="columns eight tutorial">
{%- if page_language != "en" and current_tutorial -%}
{%- capture urlprefix -%}/{{ language.urlprefix }}/{%- endcapture -%}
<div class="sidenote">
<p>This translation is community contributed and may not be up to date. We only maintain the English version of the documentation. <a href="{{ page.url | replace: urlprefix, "/" }}">Read this tutorial in English</a></p>
</div>
{%- endif -%}
<div data-pagefind-body>
{%- if page.difficulty -%}
<p style="margin-top: 0;"><span class="difficulty-tag">{{ page.difficulty }}</span></p>
{%- endif -%}
{% include anchor_headings.html html=content anchorClass="anchor-link" %}
</div>
</div>
<div class="columns two">
{%- if site.data.languageindex.size > 1 and current_tutorial -%}
<input class="toggle" type="checkbox" checked/>
<label class="togglelabel">Languages</label>
<ul class="nobullet">
{%- for l in site.data.languageindex -%}
{%- if l.active and current_tutorial.languages contains l.language -%}
<li style="padding-left: 2rem;">
{%- if l.language == "en" -%}
<a href='{{ current_tutorial.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- elsif current_tutorial.languages contains l.language -%}
<a href='/{{ l.urlprefix }}{{ current_tutorial.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- endif -%}
</li>
{%- endif -%}
{%- endfor -%}
</ul>
<hr/>
{%- endif -%}
<p>
Did you spot an error or do you have a suggestion? Please let us know on GitHub!
</p>
{% include secondary_button.html text="GITHUB" link="https://github.com/defold/doc" %}
{% include secondary_button.html text="GITHUB" link=github_link %}
</div>
</div>
</div>
Expand Down
49 changes: 33 additions & 16 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ def get_language_specific_dir(language, dir):
dir = os.path.join(language, dir)
return dir


def get_index_item_languages(item, languages):
item_languages = []
if not item["path"].startswith("http"):
path = item["path"][1:]
# foo/bar/#anchor -> foo/bar
# foo/bar#anchor -> foo/bar
path = re.sub(r"/?\#.*", "", path)
for language in languages["languages"].keys():
if os.path.exists(get_language_specific_dir(language, path + ".md")):
item_languages.append(language)
return item_languages

def update_file_links_with_lang(filename, pattern, language):
# Open the file and read its content
with open(filename, 'r') as f:
Expand Down Expand Up @@ -485,13 +498,22 @@ def process_docs(download = False):
for filename in find_files(shared_includes_dst_dir, "*.md"):
process_doc_file(filename, language)

print("...tutorials")
tutorials_src_dir = os.path.join(DOC_DIR, "docs", "en", "tutorials")
tutorials_dst_dir = "tutorials"
rmcopytree(tutorials_src_dir, tutorials_dst_dir)
for filename in find_files(tutorials_dst_dir, "*.md"):
process_doc_file(filename, "en")
append_frontmatter(filename, { "layout": "tutorial" })
for language in languages["languages"].keys():
print("...tutorials ({})".format(language))
tutorials_src_dir = os.path.join(DOC_DIR, "docs", language, "tutorials")
if os.path.exists(tutorials_src_dir):
tutorials_dst_dir = get_language_specific_dir(language, "tutorials")
rmcopytree(tutorials_src_dir, tutorials_dst_dir)
for filename in find_files(tutorials_dst_dir, "*.md"):
process_doc_file(filename, language)
append_frontmatter(filename, {
"language": language,
"layout": "tutorial",
})
if language != "en":
update_file_links_with_lang(filename, r'/manuals/[^)#]+', language)
update_file_links_with_lang(filename, r'/tutorials/[^)#]+', language)
replace_in_file(filename, r"\.\.\/images\/", r"/tutorials/images/")

print("...courses")
courses_src_dir = os.path.join(DOC_DIR, "docs", "en", "courses")
Expand All @@ -505,15 +527,10 @@ def process_docs(download = False):
print("...index (incl. languages)")
for section in index["navigation"]["manuals"]:
for item in section["items"]:
item["languages"] = []
if not item["path"].startswith("http"):
path = item["path"][1:]
# foo/bar/#anchor -> foo/bar
# foo/bar#anchor -> foo/bar
path = re.sub(r"/?\#.*", "", path)
for language in languages["languages"].keys():
if os.path.exists(get_language_specific_dir(language, path + ".md")):
item["languages"].append(language)
item["languages"] = get_index_item_languages(item, languages)
for item in index["navigation"]["tutorials"]:
if not item["path"].startswith("http"):
item["languages"] = get_index_item_languages(item, languages)
write_as_json(index_file, index)

print("...shared images")
Expand Down
Loading