Skip to content

Commit

Permalink
First pass at double header display
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Dec 19, 2020
1 parent 1674062 commit 33a4388
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 43 deletions.
4 changes: 4 additions & 0 deletions docs/_static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function openModal(modal) {
modal.hidden = false;
}

function changeDocumentation(element) {
window.location = element.value;
}

function updateSetting(element) {
localStorage.setItem(element.name, element.checked);
if (element.name in settings) {
Expand Down
167 changes: 149 additions & 18 deletions docs/_static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ Historically however, thanks to:
/* CSS variables would go here */
:root {
--font-family: 'Georgia', 'Yu Gothic', 'Noto Sans CJK JP Regular', serif;

--primary-accent: #0a0a0a;
--secondary-accent: #171717;
--primary-text: #fff;
--secondary-text: #fff;
--settings: #fff;
--settings-hover: #ccc;
--main-background: #fff;
--link-text: #2591c4;
--link-hover-text: #0b3a44;
Expand All @@ -32,7 +37,12 @@ Historically however, thanks to:
--nav-text: #444;
--nav-hover-text: #444;
--nav-header-text: #333;
--search-border: #ccc;
--search-border: #5a5a5c;
--search-background: #171717;
--search-text: #fff;
--search-focus: #3399ff;
--search-button: #b1b1b1;
--search-button-hover: #686868;
--footer-text: #555;
--footer-link: #444;
--hr-border: #b1b4b6;
Expand Down Expand Up @@ -83,7 +93,6 @@ Historically however, thanks to:
--nav-text: rgba(255,255,255,0.7);
--nav-hover-text: rgba(255,255,255,0.5);
--nav-header-text: rgba(255,255,255,0.87);
--search-border: #ccc;
--footer-text: #555;
--footer-link: #444;
--hr-border: #b1b4b6;
Expand Down Expand Up @@ -161,9 +170,10 @@ body {
min-height: 100%;
grid-auto-rows: min-content auto min-content;
grid-template-areas:
"h"
"n"
"s"
"c"
"h"
"f";
}

Expand All @@ -187,11 +197,40 @@ a:hover {

header {
grid-area: h;
font-size: 90%;
/* does not show up on mobile */
background-color: var(--main-background);
color: var(--primary-text);
}

header > nav {
display: flex;
flex-direction: row;
justify-content: space-evenly;
}

header > nav > a {
color: var(--primary-text);
}

.main-heading {
display: none;
}

.sub-header {
grid-area: n;
background-color: var(--secondary-accent);
color: var(--secondary-text);
/* not shown on mobile */
display: none;
}

.sub-header > .settings {
color: var(--settings);
}

.sub-header > .settings:hover {
color: var(--settings-hover);
}

/* footer stuff */
footer {
grid-area: f;
Expand Down Expand Up @@ -276,16 +315,65 @@ aside h3 {

/* search button stuff */

.searchformwrapper > form input, button {
.searchwrapper {
display: flex;
align-items: stretch;
}

.searchwrapper > input[type=search] {
font-family: "Roboto", Corbel, Avenir, "Lucida Grande", "Lucida Sans", sans-serif;
font-size: 1em;
}

.searchwrapper > input[type=search],
.searchwrapper > button[type=submit] {
background-color: var(--search-background);
border: none;
color: var(--search-text);
padding: 0.5em;
min-height: 2.5em;
flex: 9;
}

.searchwrapper {
border-bottom: 1px solid var(--search-border);
}

.searchwrapper:focus-within {
border-bottom: 1px solid var(--search-focus);
}

/* .searchwrapper > input[type=search] {
border: 1px solid var(--search-border);
padding: 0.25em;
flex-grow: 2;
border-right: none;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.searchformwrapper > form button[type="submit"] {
.searchwrapper > input[type=search]:focus,
button[type=submit]:focus ~ input[type=search] {
border: 1px solid var(--search-focus);
border-right: none;
} */

.searchwrapper > button[type=submit] {
color: var(--search-button);
/* border: 1px solid var(--search-border); */
/* border-left: none; */
/* border-bottom-right-radius: 4px; */
/* border-top-right-radius: 4px; */
cursor: pointer;
flex: 1;
}

/* .searchwrapper > button[type=submit]:focus,
input[type=search]:focus ~ button[type=submit] {
border: 1px solid var(--search-focus);
border-left: none;
margin-right: 0.5em;
flex-grow: 8;
} */

.searchwrapper > button[type=submit]:hover {
background-color: var(--search-border);
}

/* main content area */
Expand Down Expand Up @@ -752,7 +840,7 @@ table.docutils tbody tr td ol.last {
}

/* hide the welcome text */
div#welcome-to-discord-py > h1 {
section#welcome-to-discord-py > h1 {
display: none;
}

Expand All @@ -773,14 +861,33 @@ div.code-block-caption {
.main-grid {
grid-template-areas:
"h h h h h h"
"n n n n n n"
"s c c c c c"
"s f f f f f";
}

header {
background-color: var(--primary-accent);
}

header > nav {
justify-content: flex-end;
}

.main-heading {
margin-right: auto;
display: unset;
}

header > nav a:not(.main-heading) {
margin: 0 0.5em;
}

.sub-header {
display: flex;
align-items: center;
}

aside {
top: initial;
position: initial;
Expand All @@ -792,10 +899,6 @@ div.code-block-caption {
color: var(--nav-header-text);
}

header > nav {
float: right;
}

#sidebar {
display: inline-block;
position: sticky;
Expand Down Expand Up @@ -828,11 +931,39 @@ div.code-block-caption {
/* sidebar takes up 20% of the inner area */
grid-template-columns: repeat(16, 1fr);
grid-template-areas:
"s s h h h h h h h h h h h h h h"
"h h h h h h h h h h h h h h h h"
"n n n n n n n n n n n n n n n n"
"s s . . . c c c c c c c c . . ."
"s s f f f f f f f f f f f f f f"
}

header > nav {
margin-left: 18.75%;
margin-right: 18.75%;
}

.sub-header > label {
margin-left: 18.75%;
margin-right: 1em;
}

.sub-header > select {
margin-right: auto;
}

.sub-header > .settings {
margin-right: 18.75%;
margin-left: 1em;
}

.sub-header > .search {
width: 20%;
}

.sub-header .fa-cog {
font-size: 1.5em;
}

main img {
display: block;
margin-left: auto;
Expand Down
55 changes: 30 additions & 25 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,48 @@
<body>
{%- block header %}{% endblock %}
<div class="main-grid">
{#- The relative links component #}
{#- The main navigation header #}
<header class="grid-item">
<nav>
<!--{%- for rellink in rellinks | reverse %}
<a href="{{ pathto(rellink[0])|e }}" title="{{ rellink[1]|striptags|e }}"
{{ accesskey(rellink[2]) }}>{{ rellink[3] }}</a> |
{%- endfor %}-->
<a title="settings" accesskey="S" onclick="openModal(settingsModal);"><i class='fas fa-cog'></i></a>
{#- No breadcrumbs. But if they're gonna appear they'll be here #}
<a href="{{ pathto(master_doc)|e }}" class="main-heading">discord.py</a>
<a href="https://github.com/Rapptz/discord.py">GitHub</a>
<a href="{{ discord_invite }}">{{ _('Discord') }}</a>
<a href="{{ pathto('faq') }}">FAQ</a>
{#- If we have more links we can put them here #}
</nav>
</header>
{#- The sub-header with search and extension related selection #}
<div class="sub-header grid-item">
<label for="documentation_select">{{ _('View Documentation For') }}</label>
<select id="documentation_select" onchange="changeDocumentation(this)">
{%- if pagename is prefixedwith 'ext/' %}
<option value="{{ pathto(master_doc)|e }}">discord</option>
{%- else %}
<option value="{{ pathto(pagename) }}" selected>discord</option>
{%- endif %}
{%- for ext, p in discord_extensions %}
<option value="{{ pathto(p + '/index')|e }}" {% if pagename is prefixedwith p %}selected{% endif %}>{{ ext }}</option>
{%- endfor %}
</select>
<form role="search" class="search" action="search.html" method="get">
<div class="searchwrapper">
<input type="search" name="q" placeholder="{{ _('Search documentation') }}" />
<button type="submit">
<i class="fas fa-search"></i>
</button>
</div>
</form>
<a accesskey="S" class="settings" onclick="openModal(settingsModal);"><i class='fas fa-cog'></i></a>
</div>
{#- The sidebar component #}
<aside class="grid-item">
<span id="hamburger-toggle">
<i class="fa fa-bars"></i>
</span>
<span id="settings-toggle" onclick="openModal(settingsModal);">
<span id="settings-toggle" class="settings" onclick="openModal(settingsModal);">
<i class='fas fa-cog'></i>
</span>
<div id="sidebar">
{#- This is manually unrolled from the original layout #}
<div id="searchbox" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<button type="submit">
<i class="fas fa-search"></i>
</button>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">
$("#searchbox").show(0);
</script>
{%- include "localtoc.html" %}
</div>
</aside>
Expand Down
9 changes: 9 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
# a list of builtin themes.
html_theme = 'basic'

html_context = {
'discord_invite': 'https://discord.gg/r3sSKJJ',
'discord_extensions': [
('discord.ext.commands', 'ext/commands'),
('discord.ext.tasks', 'ext/tasks'),
],
}

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
Expand Down Expand Up @@ -326,3 +334,4 @@
def setup(app):
if app.config.language == 'ja':
app.config.intersphinx_mapping['py'] = ('https://docs.python.org/ja/3', None)
app.config.html_context['discord_invite'] = 'https://discord.gg/nXzj3dg'
7 changes: 7 additions & 0 deletions docs/extensions/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def write_genindex(self) -> None:
else:
self.handle_page('genindex', genindexcontext, 'genindex.html')


def add_custom_jinja2(app):
env = app.builder.templates.environment
env.tests['prefixedwith'] = str.startswith
env.tests['suffixedwith'] = str.endswith

def get_builder(app):
"""This is necessary because RTD injects their own for some reason."""
try:
Expand All @@ -56,3 +62,4 @@ def get_builder(app):
def setup(app):
app.set_translator('html', DPYHTML5Translator, override=True)
app.add_builder(get_builder(app), override=True)
app.connect('builder-inited', add_custom_jinja2)

0 comments on commit 33a4388

Please sign in to comment.