Skip to content

Commit

Permalink
chore: added layout.html, added basic file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Feb 8, 2023
1 parent eace094 commit 0635914
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ docs/_build

.env
.astro/
package-lock.json
node_modules/
npm-debug.log*
Empty file added README.md
Empty file.
20 changes: 20 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@

project = "Shibuya"
copyright = "2023, Hsiaoming Yang"
author = "Hsiaoming Yang"

html_theme = "shibuya"
html_baseurl = "https://shibuya.lepture.com"
html_logo = "https://typlog.com/assets/logo-black.svg"

html_theme_options = {
"logo_target": "/",
"light_logo": "https://typlog.com/assets/logo-black.svg",
"dark_logo": "https://typlog.com/assets/logo-white.svg",

"head_links": [
{
"name": "Documentation",
"url": "/"
},
]
}
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Shibuya for Sphinx
==================

haha
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "shibuya",
"version": "1.0.0",
"scripts": {
"build": "esbuild static/index.js --bundle --outfile=shibuya/theme/shibuya/static/shibuya.js",
"dev": "npm run build -- --watch"
},
"devDependencies": {
"esbuild": "^0.17.6",
"tailwindcss": "^3.2.4"
}
}
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[project]
name = "sphinx-shibuya"
name = "shibuya"
description = "A clean, responsive, and customisable Sphinx documentation theme with light/dark mode."
dynamic = ["version"]
readme = "README.rst"
readme = "README.md"

requires-python = ">=3.7"
dependencies = [
Expand Down Expand Up @@ -34,3 +34,10 @@ classifiers = [

[project.urls]
GitHub = "https://github.com/lepture/shibuya"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = {attr = "shibuya.__version__"}
2 changes: 1 addition & 1 deletion serve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from livereload import Server, shell

app = Server()
app.watch("sphinx_shibuya/src", shell("make build-docs"))
app.watch("src", shell("make build-docs"))
app.watch("docs", shell("make build-docs"))
app.serve(root="build/_html")
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup

# for pip install -e
setup()
15 changes: 0 additions & 15 deletions shibuya/__init__.py

This file was deleted.

21 changes: 0 additions & 21 deletions shibuya/theme/shibuya/layout.html

This file was deleted.

4 changes: 0 additions & 4 deletions shibuya/theme/shibuya/theme.conf

This file was deleted.

31 changes: 31 additions & 0 deletions src/shibuya/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Dict, Any
from pathlib import Path
from sphinx.builders.html import StandaloneHTMLBuilder
from .context import (
BASE_CSS_VARIABLES,
LIGHT_CSS_VARIABLES,
DARK_CSS_VARIABLES,
css_to_dict,
)

__version__ = '1.0.0'

THEME_PATH = (Path(__file__).parent / "theme" / "shibuya").resolve()


def _html_page_context(app, pagename: str, templatename: str, context: Dict[str, Any], doctree):
assert isinstance(app.builder, StandaloneHTMLBuilder)
context["shibuya_base_css_variables"] = css_to_dict(BASE_CSS_VARIABLES)
context["shibuya_light_css_variables"] = css_to_dict(LIGHT_CSS_VARIABLES)
context["shibuya_dark_css_variables"] = css_to_dict(DARK_CSS_VARIABLES)


def setup(app):
"""Entry point for sphinx theming."""
app.add_html_theme("shibuya", str(THEME_PATH))
app.connect("html-page-context", _html_page_context)
return {
"parallel_read_safe": True,
"parallel_write_safe": True,
"version": __version__,
}
32 changes: 32 additions & 0 deletions src/shibuya/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BASE_CSS_VARIABLES = """
--sy-f-sys: -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Droid Sans, Helvetica Neue;
--sy-f-latin: Inter, var(--sy-f-sys);
--sy-f-cjk: PingFang SC, Hiragino Sans GB, Droid Sans Fallback, Microsoft YaHei;
--sy-f-heading: var(--sy-f-latin), var(--sy-f-cjk), sans-serif;
--sy-f-text: var(--sy-f-latin), var(--sy-f-cjk), sans-serif;
--sy-c-text: rgba(var(--sy-rc-text), 0.86);
--sy-c-divider: var(--sy-rc-text, 0.1);
"""

LIGHT_CSS_VARIABLES = """
--sy-rc-bg: 255, 255, 255;
--sy-rc-text: 0, 0, 0;
--sy-c-bg: #fff;
--sy-c-bg-weak: #f9f9f9;
"""

DARK_CSS_VARIABLES = """
--sy-rc-bg: 18, 18, 18;
--sy-rc-text: 255, 255, 255;
--sy-c-bg: rgba(var(--sy-rc-bg), 0.86);
"""

def css_to_dict(text: str):
css_vars = {}
for line in text.strip().splitlines():
if not line:
continue
line = line.rstrip(";")
key, value = line.split(':')
css_vars[key.strip()] = value.strip()
return css_vars
33 changes: 33 additions & 0 deletions src/shibuya/theme/shibuya/components/css_variables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{%- macro declare_css_vars(sys_vars, user_vars) -%}
{%- if user_vars -%}
{%- for name in sys_vars -%}
{%- if name in user_vars -%}
{{ name }}:{{user_vars[name]}};
{%- else -%}
{{ name }}:{{sys_vars[name]}};
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- for name in sys_vars -%}
{{ name }}:{{sys_vars[name]}};
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}

<style>
:root {
{{ declare_css_vars(shibuya_base_css_variables, theme_base_css_variables) }}
{{ declare_css_vars(shibuya_light_css_variables, theme_light_css_variables) }}
}
@media not print {
@media (prefers-color-scheme: dark) {
{{ declare_css_vars(shibuya_dark_css_variables, theme_light_css_variables) }}
}
html[data-theme="light"] {
{{ declare_css_vars(shibuya_light_css_variables, theme_light_css_variables) }}
}
html[data-theme="dark"] {
{{ declare_css_vars(shibuya_dark_css_variables, theme_light_css_variables) }}
}
}
</style>
Empty file.
Empty file.
Empty file.
70 changes: 70 additions & 0 deletions src/shibuya/theme/shibuya/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html {% if language is not none %} lang="{{ language }}"{% endif %}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{%- block htmltitle -%}
<title>{{ title|striptags|e }}{{ titlesuffix }}</title>
{% endblock %}
{%- block linktags %}
{%- if hasdoc('about') -%}
<link rel="author" title="{{ _('About these documents') }}" href="{{ pathto('about') }}" />
{%- endif -%}
{%- if hasdoc('genindex') -%}
<link rel="index" title="{{ _('Index') }}" href="{{ pathto('genindex') }}" />
{%- endif -%}
{%- if hasdoc('search') -%}
<link rel="search" title="{{ _('Search') }}" href="{{ pathto('search') }}" />
{%- endif -%}
{%- if hasdoc('copyright') -%}
<link rel="copyright" title="{{ _('Copyright') }}" href="{{ pathto('copyright') }}" />
{%- endif -%}
{%- if next -%}
<link rel="next" title="{{ next.title|striptags|e }}" href="{{ next.link|e }}" />
{%- endif -%}
{%- if prev -%}
<link rel="prev" title="{{ prev.title|striptags|e }}" href="{{ prev.link|e }}" />
{%- endif -%}
{%- if pageurl %}
<link rel="canonical" href="{{ pageurl|e }}" />
{%- endif %}
{%- endblock linktags %}
{%- if favicon_url -%}
<link rel="shortcut icon" href="{{ favicon_url|e }}"/>
{%- endif %}

{%- block styles -%}
{%- for css in css_files -%}
{% if css|attr("filename") -%}
{{ css_tag(css) }}
{%- else -%}
<link rel="stylesheet" href="{{ pathto(css, 1)|e }}" type="text/css" />
{%- endif %}
{% endfor -%}
{% include "components/css_variables.html" with context %}
{% block theme_styles %}{% endblock %}
{%- endblock -%}
{% block extrahead %}{% endblock %}
{% include "partials/meta_head.html" %}
</head>
<body>
<div class="document">
{%- block header -%}
{% include "components/site_header.html" with context %}
{%- endblock -%}

{% block body %}{% endblock %}

{%- block footer -%}
{% include "components/site_footer.html" with context %}
{%- endblock -%}
</div>

{%- block scripts -%}
{%- for js in script_files %}
{{ js_tag(js) }}
{%- endfor %}
{% block theme_scripts %}{% endblock %}
{%- endblock %}
</body>
</html>
File renamed without changes.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions src/shibuya/theme/shibuya/static/shibuya.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(() => {
})();
13 changes: 13 additions & 0 deletions src/shibuya/theme/shibuya/theme.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[theme]
inherit = basic

[options]
logo_target =
light_logo =
dark_logo =

base_css_variables =
light_css_variables =
dark_css_variables =

head_links =
Empty file added static/index.js
Empty file.

0 comments on commit 0635914

Please sign in to comment.