Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public draft feature #725

Merged
merged 7 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion content/learn/index.md → content/learn/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title = "Learn Bevy"
template = "learn.html"
[extra]
header_message = "Learn"
+++
+++
8 changes: 8 additions & 0 deletions sass/_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
color: #c8c864;
}

body:not(.show_drafts) .public_draft:not(.active_draft) {
display: none !important;
}

.public_draft > div > a {
color: #c8c864 !important;
}

.anchor-link, .anchor-link:focus, .anchor-link:hover, .anchor-link:active, .anchor-link:hover, .anchor-link:link, .anchor-link:visited {
margin-left: 0.3rem;
color: #505050;
Expand Down
16 changes: 16 additions & 0 deletions templates/docs-section.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@

{% for p in all_sections %}
{% set section_obj = get_section(path=p) %}
{% set parent_section_path = section_obj.components | slice(end=-1) | concat(with="_index.md") | join(sep="/") %}
{% set parent_section = get_section(path=parent_section_path) %}

{% if found_current %}
{% if section_obj.extra and section_obj.extra.public_draft %}
{% continue %}
{% elif parent_section.extra and parent_section.extra.public_draft %}
{% continue %}
{% endif %}
{% set_global next_section = section_obj %}
{% break %}
{% endif %}
Expand All @@ -63,6 +70,11 @@
{% continue %}
{% endif %}

{% if section_obj.extra and section_obj.extra.public_draft %}
{% continue %}
{% elif parent_section.extra and parent_section.extra.public_draft %}
{% continue %}
{% endif %}
{% set_global prev_section = section_obj %}
{% endfor %}

Expand All @@ -76,6 +88,10 @@ <h1>
<span class="docs-page-subtitle">({{section.extra.subtitle}})</span>
{% endif %}
</h1>
<a class="example__github" href="https://github.com/bevyengine/bevy-website/tree/main/content/{{ section.relative_path }}">
cart marked this conversation as resolved.
Show resolved Hide resolved
<i class="icon icon--github"></i> Improve this page
</a>

<div class="media-content">{{ section.content | safe }}</div>
<div class="docs-footer">
<nav class="docs-footer__nav">
Expand Down
15 changes: 15 additions & 0 deletions templates/layouts/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% import "macros/header.html" as header_macros %}
{% import "macros/public_draft.html" as public_draft %}

{% if section and section.title %}
{% if section.path is starting_with("/learn/book/") %}
Expand Down Expand Up @@ -117,9 +118,23 @@
</header>
<main class="layout__content">
<div class="container">
{% if section %}
{{ public_draft::warning(section=section) }}
{% endif %}
{% block content %}{% endblock %}
</div>
</main>
</div>
<script>
const search_params = new URLSearchParams(window.location.search);
if (search_params.has("show_drafts") || document.cookie.indexOf("show_drafts") >= 0) {
if (search_params.get("show_drafts") === "0") {
document.cookie = "show_drafts=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC";
} else {
document.cookie = "show_drafts=1;path=/"
document.body.classList.add('show_drafts');
}
}
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/macros/disallow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro generate_disallows(disallow, section) %}
{% if disallow or section and section.extra and section.extra.public_draft %}
Disallow: {{section.path}}
{% for s in section.subsections %}
{{ self::generate_disallows(disallow=true, section=get_section(path=s)) }}
{% endfor %}
{% else %}
{% for s in section.subsections %}
{{ self::generate_disallows(disallow=false, section=get_section(path=s)) }}
{% endfor %}
{% endif %}
{% endmacro generate_disallows %}
25 changes: 16 additions & 9 deletions templates/macros/docs.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
{% macro docs_menu_row(prefix, section_path) %}
{% set section = get_section(path=section_path) %}
{% set is_in_branch = section.path in current_path %}
{% set is_active = current_path == section.path %}
{% set id = prefix ~ '-' ~ section.path | slugify %}
{% set menu_section = get_section(path=section_path, metadata_only=true) %}
{% set is_in_branch = menu_section.path in current_path %}
{% set is_active = current_path == menu_section.path %}
{% set id = prefix ~ '-' ~ menu_section.path | slugify %}
{% set class = "tree-menu__item" %}
{% set label_class = "tree-menu__label" %}

{% if is_active %}
{% set class = class ~ " tree-menu__item--active" %}
{% endif %}

{% if section.subsections %}
{% if menu_section.extra and menu_section.extra.public_draft %}
{% set class = class ~ " public_draft" %}
{% if is_in_branch %}
{% set class = class ~ " active_draft" %}
{% endif %}
{% endif %}

{% if menu_section.subsections %}
{% set label_class = label_class ~ " tree-menu__label--with-chevron" %}
<input id="{{id}}" class="tree-menu__state" type="checkbox" {% if is_in_branch %}checked{% endif %}>
{% endif %}

<li class="{{class}}">
<div class="{{label_class}}">
<a class="tree-menu__link" href="{{section.path}}">{{ section.title }}</a>
{% if section.subsections %}
<a class="tree-menu__link" href="{{menu_section.path}}">{{ menu_section.title }}</a>
{% if menu_section.subsections %}
<label class="tree-menu__toggle" for="{{id}}">
<img class="tree-menu__chevron" src="/assets/icon-chevron-down.svg">
</label>
{% endif %}
</div>
{% if section.subsections %}
{% if menu_section.subsections %}
<ul class="tree-menu">
{% for s in section.subsections %}
{% for s in menu_section.subsections %}
{{ self::docs_menu_row(prefix=prefix, section_path=s) }}
{% endfor %}
</ul>
Expand Down
16 changes: 16 additions & 0 deletions templates/macros/public_draft.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% macro warning(current=true, section) %}
{% if section and section.extra.public_draft %}
{% set public_draft = section.extra.public_draft %}
{% set issue = public_draft / 1 %}
{% if current %}
<h1 class="warning">Looks like this page is still under development</h1>
cart marked this conversation as resolved.
Show resolved Hide resolved
<p>The page is still under development. This page and all pages under it will be hidden from search engines and menus!</p>
<p>See <a href="https://github.com/bevyengine/bevy-website/issues/{{issue}}">this issue</a> for more info</p>
{% else %}
<h1 class="warning">This page is hidden because an ancestor is hidden</h1>
{% endif %}
{% elif section.components %}
{% set next_path = section.components | slice(end=-1) | concat(with="_index.md") | join(sep="/") %}
{{ public_draft::warning(current=false, section=get_section(path=next_path)) }}
{% endif %}
{% endmacro warning %}
5 changes: 5 additions & 0 deletions templates/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% import "macros/disallow.html" as disallow_macros %}

User-agent: *
Sitemap: {{ get_url(path="sitemap.xml") }}
{{ disallow_macros::generate_disallows(disallow=false, section=get_section(path="_index.md")) }}