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
3 changes: 2 additions & 1 deletion _includes/api_c.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- assign ref = include.ref -%}
{%- assign ref_api_language = ref.info.api_language | default: ref.info.language -%}

{%- assign struct_type_list = "STRUCT~CLASS" | split:"~" -%}
{%- assign structs = ref.elements | where_exp: "item", "struct_type_list contains item.type" -%}
Expand Down Expand Up @@ -27,7 +28,7 @@ <h2 id="{{ ref.info.name | slugify }}" data-pagefind-weight="7">{{ ref.info.name
<th></th>
<th></th>
</tr>
{%- if ref.info.language == "C++" and ref.info.namespace != "" -%}
{%- if ref_api_language == "C++" and ref.info.namespace != "" -%}
{%- unless global_namespaces contains ref.info.namespace -%}
<tr>
<td>Namespace:</td>
Expand Down
25 changes: 14 additions & 11 deletions _layouts/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
{%- else -%}
{%- assign ref = site.data.ref[page.branch][clean_ref] -%}
{%- endif -%}
{%- assign page_api_language = page.api_language | default: page.language -%}
{%- assign ref_api_language = ref.info.api_language | default: ref.info.language -%}

{%- assign api_index_exclude = false -%}
{%- if page.url contains "/ref/alpha/" or page.url contains "/ref/beta/" or page.url contains "/ref/stable/" -%}
{%- if page.url contains "/ref/stable/" or page.url contains "/ref/alpha/" or page.url contains "/ref/beta/" -%}
{%- assign api_index_exclude = true -%}
{%- endif -%}
{%- if ref.info.language == "" or ref.info.language == nil -%}
{%- if ref_api_language == "" or ref_api_language == nil -%}
{%- assign api_index_exclude = true -%}
{%- endif -%}
{%- if page.pagefind_exclude -%}
Expand All @@ -26,8 +28,9 @@

{%- unless api_index_exclude -%}
<!-- Pagefind metadata and filters for API reference -->
<div style="display: none;" data-pagefind-filter="section">API {{ref.info.language}}</div>
<div style="display: none;" data-pagefind-meta="section">API {{ref.info.language}}</div>
<div style="display: none;" data-pagefind-filter="section">API</div>
<div style="display: none;" data-pagefind-meta="section">API</div>
<div style="display: none;" data-pagefind-meta="api_language">{{ ref_api_language }}</div>
{%- endunless -%}

{%- if page.url contains branch -%}
Expand Down Expand Up @@ -78,7 +81,7 @@
{%- if page.url contains r.url -%}
{%- assign textstyle = "font-weight: bolder; font-style: italic; text-decoration: none;" -%}
{%- endif -%}
<li id="{{ r.namespace }}" style="padding-bottom: 0px;"><a href="{{ r.url }}" style="{{ textstyle }}">{%- if r.language == "C++" or r.language == "C" -%}{{r.file}}{%- endif -%}{%- if r.type == "Extension" -%}{{r.name}}{%- endif -%}</a></li>
<li id="{{ r.namespace }}" style="padding-bottom: 0px;"><a href="{{ r.url }}" style="{{ textstyle }}">{%- if r.api_language == "C++" or r.api_language == "C" -%}{{r.file}}{%- endif -%}{%- if r.type == "Extension" -%}{{r.name}}{%- endif -%}</a></li>
{%- endfor -%}
</ul>
{%- else -%}
Expand All @@ -87,7 +90,7 @@
{%- if page.url contains r.url -%}
{%- assign textstyle = "font-weight: bolder; font-style: italic; text-decoration: none;" -%}
{%- endif -%}
<li id="{{ r.namespace }}" style="padding-bottom: 0px;"><a href="{{ r.url }}" style="{{ textstyle }}">{{ r.namespace }}{%- if r.language == "C++" or r.language == "C" -%}&nbsp;-&nbsp;({{r.file}}){%- endif -%}{%- if r.type == "Extension" -%}&nbsp;-&nbsp;({{r.name}}){%- endif -%}</a></li>
<li id="{{ r.namespace }}" style="padding-bottom: 0px;"><a href="{{ r.url }}" style="{{ textstyle }}">{{ r.namespace }}{%- if r.api_language == "C++" or r.api_language == "C" -%}&nbsp;-&nbsp;({{r.file}}){%- endif -%}{%- if r.type == "Extension" -%}&nbsp;-&nbsp;({{r.name}}){%- endif -%}</a></li>
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
Expand Down Expand Up @@ -136,7 +139,7 @@ <h1>API Overview</h1>
<table>
<tr>
<th>Namespace</th>
<th>{%- if page.language == "C++" or page.language == "C" -%}Include{%- elsif r.type == "Extension" -%}Library Folder{%- else -%}Name{%- endif -%}</th>
<th>{%- if page_api_language == "C++" or page_api_language == "C" -%}Include{%- elsif r.type == "Extension" -%}Library Folder{%- else -%}Name{%- endif -%}</th>
<th>Description</th>
</tr>
{%- for r in typerefs -%}
Expand All @@ -148,15 +151,15 @@ <h1>API Overview</h1>
{%- assign ref = site.data.ref[page.branch][index] -%}
{%- endif -%}

<td><a href="{{r.url}}">{%- if r.language == "C++" or r.language == "C" -%}{{ r.namespace }}{%- else -%}{{r.name}}{%- endif -%}</a></td>
<td>{%- if r.language == "C++" or r.language == "C" -%}{{r.path}}{%- else -%}{{r.namespace}}{%- endif -%}</td>
<td><a href="{{r.url}}">{%- if r.api_language == "C++" or r.api_language == "C" -%}{{ r.namespace }}{%- else -%}{{r.name}}{%- endif -%}</a></td>
<td>{%- if r.api_language == "C++" or r.api_language == "C" -%}{{r.path}}{%- else -%}{{r.namespace}}{%- endif -%}</td>
<td>{{ ref.info.brief }}</td>
</tr>
{%- endfor -%}
</table>
{%- elsif ref.info.language == "C++" -%}
{%- elsif ref_api_language == "C++" -%}
{%- include api_c.html ref=ref -%}
{%- elsif ref.info.language == "Lua" -%}
{%- elsif ref_api_language == "Lua" -%}
{%- include api_lua.html ref=ref -%}
{%- else -%}
{%- include api_c.html ref=ref -%}
Expand Down
10 changes: 8 additions & 2 deletions _layouts/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{%- if page.language -%}
{%- assign page_locale = page.locale | default: page.language -%}
{%- if page_locale -%}
{%- if page.layout == "manual" or page.layout == "tutorial" or page.layout == "faq" -%}
<!DOCTYPE html>
<html lang="{{ page.language }}">
<html lang="{{ page_locale }}">
{%- else -%}
<!DOCTYPE html>
<html lang="en">
{%- endif -%}
{%- else -%}
<!DOCTYPE html>
<html lang="en">
Expand Down
15 changes: 8 additions & 7 deletions _layouts/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@
---
{% include learnnav.html showmenu=true %}

{%- assign language = site.data.languageindex | where: "language", page.language | first -%}
{%- assign page_locale = page.locale | default: "en" -%}
{%- assign locale_info = site.data.localeindex | where: "locale", page_locale | first -%}
<div style="display: none;" data-pagefind-filter="section">FAQ</div>
<div style="display: none;" data-pagefind-meta="section">FAQ</div>
<div class="section lightest dark:dark">
<div class="container">
<div class="row">
<div class="columns ten faq">
{%- if page.language != "en" -%}
{%- capture urlprefix -%}/{{ language.urlprefix }}/{%- endcapture -%}
{%- if page_locale != "en" -%}
{%- capture urlprefix -%}/{{ locale_info.urlprefix }}/{%- endcapture -%}
<p><a href="{{ page.url | replace: urlprefix, "/" }}">Read this FAQ in English</a></p>
{%- endif -%}
{% include anchor_headings.html html=content anchorClass="anchor-link" %}
</div>
<div class="columns two">
{%- if site.data.languageindex.size > 1 -%}
{%- if site.data.localeindex.size > 1 -%}
<input class="toggle" type="checkbox" checked/>
<label class="togglelabel">Languages</label>
<ul class="nobullet">
{%- for l in site.data.languageindex -%}
{%- for l in site.data.localeindex -%}
{%- if l.active -%}
<li style="padding-left: 2rem;">
{%- if l.language == "en" -%}
{%- if l.locale == "en" -%}
<a href='/faq/faq' style="text-decoration: none;">{{ l.name }}</a>
{%- else -%}
<a href='/{{ l.language }}/faq/faq' style="text-decoration: none;">{{ l.name }}</a>
<a href='/{{ l.locale }}/faq/faq' style="text-decoration: none;">{{ l.name }}</a>
{%- endif -%}
</li>
{%- endif -%}
Expand Down
29 changes: 15 additions & 14 deletions _layouts/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<div style="display: none;" data-pagefind-meta="section">Manuals</div>
{% include learnnav.html showmenu=true %}

{%- assign language = site.data.languageindex | where: "language", page.language | first -%}
{%- assign page_locale = page.locale | default: "en" -%}
{%- assign locale_info = site.data.localeindex | where: "locale", page_locale | first -%}
{%- for section in site.data.learnindex.navigation.manuals -%}
{%- for manual in section.items -%}
{% comment %}https://stackoverflow.com/a/37026674{% endcomment %}
Expand Down Expand Up @@ -37,10 +38,10 @@
<ul class="nobullet">
{%- for manual in section.items -%}
<li style="padding-left: 2rem;">
{%- if language.language == "en" -%}
{%- if page_locale == "en" -%}
<a href="{{ manual.path }}" style="text-decoration: none;">{{ manual.name }}</a>
{%- elsif manual.languages contains language.language -%}
<a href="/{{ language.urlprefix }}{{ manual.path }}" style="text-decoration: none;">{{ manual.name }}</a>
{%- elsif manual.locales contains page_locale -%}
<a href="/{{ locale_info.urlprefix }}{{ manual.path }}" style="text-decoration: none;">{{ manual.name }}</a>
{%- else -%}
<a href="{{ manual.path }}" style="text-decoration: none;">{{ manual.name }} (English)</a>
{%- endif -%}
Expand All @@ -57,10 +58,10 @@
{%- for section in site.data.learnindex.navigation.manuals -%}
<option value="">{{ section.name }}</option>
{%- for manual in section.items -%}
{%- if language.language == "en" -%}
{%- if page_locale == "en" -%}
<option value="{{ manual.path }}" {% if page.url contains manual.path %}selected{% endif %}> - {{ manual.name }}</option>
{%- elsif manual.languages contains language.language -%}
<option value="/{{ language.urlprefix }}{{ manual.path }}" {% if page.url contains manual.path %}selected{% endif %}> - {{ manual.name }}</option>
{%- elsif manual.locales contains page_locale -%}
<option value="/{{ locale_info.urlprefix }}{{ manual.path }}" {% if page.url contains manual.path %}selected{% endif %}> - {{ manual.name }}</option>
{%- else -%}
<option value="{{ manual.path }}" {% if page.url contains manual.path %}selected{% endif %}> - {{ manual.name }}</option>
{%- endif -%}
Expand All @@ -70,8 +71,8 @@
</div>
</div>
<div class="columns eight manual">
{%- if page.language != "en" -%}
{%- capture urlprefix -%}/{{ language.urlprefix }}/{%- endcapture -%}
{%- if page_locale != "en" -%}
{%- capture urlprefix -%}/{{ locale_info.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 manual in English</a></p>
</div>
Expand All @@ -93,19 +94,19 @@

<hr/>

{%- if site.data.languageindex.size > 1 -%}
{%- if site.data.localeindex.size > 1 -%}
<input class="toggle" type="checkbox" checked/>
<label class="togglelabel">Languages</label>
<ul class="nobullet">
{%- for l in site.data.languageindex -%}
{%- for l in site.data.localeindex -%}
{%- if l.active -%}
<li style="padding-left: 2rem;">
{%- if l.language == "en" -%}
{%- if l.locale == "en" -%}
<a href='{{ current_manual.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- elsif current_manual.languages contains l.language -%}
{%- elsif current_manual.locales contains l.locale -%}
<a href='/{{ l.urlprefix }}{{ current_manual.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- else -%}
<a href='/{{ l.language }}/manuals/introduction' style="text-decoration: none;">{{ l.name }}</a>
<a href='/{{ l.locale }}/manuals/introduction' style="text-decoration: none;">{{ l.name }}</a>
{%- endif -%}
</li>
{%- endif -%}
Expand Down
30 changes: 15 additions & 15 deletions _layouts/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<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 page_locale = page.locale | default: "en" -%}
{%- assign locale_info = site.data.localeindex | where: "locale", page_locale | 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/" -%}
Expand Down Expand Up @@ -35,10 +35,10 @@
{%- endif -%}
<li style="padding-left: 2rem;">
{%- if tutorial.path contains "/tutorials/" -%}
{%- if page_language == "en" -%}
{%- if page_locale == "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>
{%- elsif tutorial.locales contains page_locale -%}
<a href="/{{ locale_info.urlprefix }}{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }}</a>
{%- else -%}
<a href="{{ tutorial.path }}" style="text-decoration: none;">{{ tutorial.name }} (English)</a>
{%- endif -%}
Expand All @@ -53,10 +53,10 @@
<select class="dropdownmenu" onchange="location = this.value;">
{% for tutorial in site.data.learnindex.navigation.tutorials %}
{%- if tutorial.path contains "/tutorials/" -%}
{%- if page_language == "en" -%}
{%- if page_locale == "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>
{%- elsif tutorial.locales contains page_locale -%}
<option value="/{{ locale_info.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 -%}
Expand All @@ -68,8 +68,8 @@
</div>
</div>
<div class="columns eight tutorial">
{%- if page_language != "en" and current_tutorial -%}
{%- capture urlprefix -%}/{{ language.urlprefix }}/{%- endcapture -%}
{%- if page_locale != "en" and current_tutorial -%}
{%- capture urlprefix -%}/{{ locale_info.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>
Expand All @@ -82,16 +82,16 @@
</div>
</div>
<div class="columns two">
{%- if site.data.languageindex.size > 1 and current_tutorial -%}
{%- if site.data.localeindex.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 -%}
{%- for l in site.data.localeindex -%}
{%- if l.active and current_tutorial.locales contains l.locale -%}
<li style="padding-left: 2rem;">
{%- if l.language == "en" -%}
{%- if l.locale == "en" -%}
<a href='{{ current_tutorial.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- elsif current_tutorial.languages contains l.language -%}
{%- elsif current_tutorial.locales contains l.locale -%}
<a href='/{{ l.urlprefix }}{{ current_tutorial.path }}' style="text-decoration: none;">{{ l.name }}</a>
{%- endif -%}
</li>
Expand Down
40 changes: 40 additions & 0 deletions search.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,45 @@ <h3>Results</h3>

<script>
window.addEventListener('DOMContentLoaded', (event) => {
const normalizeSearchTerm = (term) => {
return (term || "")
.toLowerCase()
.trim()
.replace(/[\.`~!@#\$%\^&\*\(\)\{\}\[\]\\\|:;'",<>\/\?\-]/g, "")
.replace(/\s{2,}/g, " ")
.trim();
};

let currentQuery = "";

const boostExactSubResultMatch = (result) => {
const normalizedQuery = normalizeSearchTerm(currentQuery);
if (!normalizedQuery || !Array.isArray(result.sub_results)) {
return result;
}

for (const subResult of result.sub_results) {
const normalizedTitle = normalizeSearchTerm(subResult.title || "");
if (normalizedTitle !== normalizedQuery) {
continue;
}

const locations = Array.isArray(subResult.locations) ? subResult.locations : [];
const lastLocation = locations.length ? locations[locations.length - 1] : 0;
subResult.locations = locations.concat(Array(8).fill(lastLocation));
break;
}

return result;
};

new PagefindUI({
element: "#pagefind-search",
pageSize: 10,
showSubResults: true,
showImages: false,
excerptLength: 25,
processResult: boostExactSubResultMatch,
resetStyles: false,
showEmptyFilters: true,
openFilters: ['section']
Expand All @@ -36,6 +69,7 @@ <h3>Results</h3>
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('q');
if (query) {
currentQuery = query;
// Wait for Pagefind UI to initialize then set query
setTimeout(() => {
const searchInput = document.querySelector('#pagefind-search input[type="text"]');
Expand All @@ -47,5 +81,11 @@ <h3>Results</h3>
}
}, 100);
}

document.addEventListener('input', (event) => {
if (event.target && event.target.matches('#pagefind-search input[type="text"]')) {
currentQuery = event.target.value;
}
});
});
</script>
Loading
Loading