Skip to content

Commit

Permalink
Refactor the theme common files, designed to be shared by multiple th…
Browse files Browse the repository at this point in the history
…emes
  • Loading branch information
saowang committed Oct 25, 2020
1 parent cd58738 commit 0de2127
Show file tree
Hide file tree
Showing 73 changed files with 258 additions and 254 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -40,7 +40,7 @@ jobs:
LAST_TAG=$(git describe --tags --abbrev=0)
git log ${LAST_TAG}..HEAD --no-merges --format="- %h %s @%an" > action.changelog.md
sed -i "s/${LAST_TAG:1}/${VERSION}/g" jekyll-rtd-theme.gemspec
sed -i "s/${LAST_TAG:1}/${VERSION}/g" _includes/reset/version.liquid
sed -i "s/${LAST_TAG:1}/${VERSION}/g" _includes/rest/variables.liquid
- name: Prettier check and Build theme assets!
run: |
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
@@ -1,5 +1,4 @@
source "https://gems.ruby-china.com"
# source "https://rubygems.org"
source "https://rubygems.org" # source "https://gems.ruby-china.com"

gemspec

Expand Down
4 changes: 0 additions & 4 deletions README.md
Expand Up @@ -66,13 +66,9 @@ mermaid:
custom: # mermaid link
initialize: # mermaid options, default: {}

# also available via file: _include/assets/custom.scss
scss:

# also available via file: _include/assets/custom.js
script:

# also available via file: _data/translate.yml
translate:
# shortcodes
danger:
Expand Down
11 changes: 6 additions & 5 deletions _config.yml
Expand Up @@ -3,10 +3,10 @@ description: Opinionated standard documentation theme, with few options, but eve

theme: null

# debug:
# compress: true
# dist: false
# shortcodes: true
debug:
compress: true
dist: false
shortcodes: true

readme_index:
with_frontmatter: true
Expand All @@ -19,9 +19,10 @@ plugins:
exclude:
- Makefile
- CNAME
- LICENSE
- update.sh
- Gemfile
- Gemfile.lock
- LICENSE
- requirements.txt
- node_modules
- package.json
Expand Down
9 changes: 9 additions & 0 deletions _includes/README.md
@@ -0,0 +1,9 @@
# Document Statement

## templates

Template files for this theme

## common

Some common variables and code snippets are designed to be shared by multiple themes
21 changes: 0 additions & 21 deletions _includes/addons/github.liquid

This file was deleted.

Empty file removed _includes/assets/custom.js
Empty file.
Empty file removed _includes/assets/custom.scss
Empty file.
26 changes: 0 additions & 26 deletions _includes/class/addons-wrap.liquid

This file was deleted.

3 changes: 3 additions & 0 deletions _includes/common/assets/data.liquid
@@ -0,0 +1,3 @@
{%- include common/rest/site_pages.liquid -%}

{{- site_pages | jsonify -}}
4 changes: 4 additions & 0 deletions _includes/common/assets/robots.liquid
@@ -0,0 +1,4 @@
User-agent: *
Allow: /

Sitemap: {{ "sitemap.xml" | absolute_url }}
12 changes: 12 additions & 0 deletions _includes/common/assets/sitemap.liquid
@@ -0,0 +1,12 @@
{%- include common/rest/site_pages.liquid -%}

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for page in site_pages -%}
<url>
<loc>{{ page.url | absolute_url | xml_escape }}</loc>
<priority>{{ page.content | size | divided_by: 2048.0 | times: 10 | ceil | divided_by: 10.0 | at_least: 0.1 | at_most: 1.0 }}</priority>
<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>
</url>
{%- endfor %}
</urlset>
@@ -1,5 +1,5 @@
self.addEventListener("activate", function (event) {
const current = ["rundocs-{{ version }}"];
const current = ["{{ theme_alias }}"];

event.waitUntil(
caches.keys().then(function (keyList) {
Expand All @@ -15,7 +15,7 @@ self.addEventListener("activate", function (event) {
});

self.addEventListener("fetch", function (e) {
if (e.request.url.match("rundocs/jekyll-rtd-theme@{{ version }}")) {
if (e.request.url.match("{{ theme_alias }}")) {
e.respondWith(
caches.match(e.request).then(function (resp) {
if (resp !== undefined) {
Expand All @@ -26,7 +26,7 @@ self.addEventListener("fetch", function (e) {
})
.then(function (resp) {
let clone = resp.clone();
caches.open("rundocs-{{ version }}").then(function (cache) {
caches.open("{{ theme_alias }}").then(function (cache) {
cache.put(e.request, clone);
});
return resp;
Expand Down
15 changes: 15 additions & 0 deletions _includes/common/core/_list.liquid
@@ -0,0 +1,15 @@
{%- include common/rest/site_pages.liquid -%}
{%- include common/rest/workdir.liquid -%}

{%- assign base = page.dir | append: "temp/" | split: "/" | size -%}
{%- assign size = workdir_level | minus: base -%}
{%- assign size_p1 = size | plus: 1 -%}

{%- assign dir = site_pages | where: "url", workdir | first %}
{% include common/rest/tabs.liquid size=size %}- [{{ dir.title | default: dir.url }}]({{ dir.url | relative_url }})

{%- for item in workdir_files %}
{% include common/rest/tabs.liquid size=size_p1 %}- [{{ item.title | default: item.name }}]({{ item.url | relative_url }})
{%- endfor -%}

{%- for workdir in workdir_dirs %}{% include common/core/_list.liquid %}{% endfor -%}
10 changes: 10 additions & 0 deletions _includes/common/core/list.liquid
@@ -0,0 +1,10 @@
{%- include common/rest/site_pages.liquid -%}
{%- include common/rest/workdir.liquid workdir=page.dir -%}

{%- for item in workdir_files %}
- [{{ item.title | default: item.name }}]({{ item.url | relative_url }})
{%- endfor -%}

{%- if include.all -%}
{%- for workdir in workdir_dirs %}{% include common/core/_list.liquid %}{% endfor -%}
{%- endif -%}
3 changes: 3 additions & 0 deletions _includes/common/google_adsense.liquid
@@ -0,0 +1,3 @@
{%- if site.google.adsense -%}
<script data-ad-client="{{ site.google.adsense }}" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
{%- endif -%}
11 changes: 11 additions & 0 deletions _includes/common/google_gtag.liquid
@@ -0,0 +1,11 @@
{%- if site.google.gtag -%}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google.gtag }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "{{ site.google.gtag }}");
</script>
{%- endif -%}
22 changes: 8 additions & 14 deletions _includes/node/links.liquid → _includes/common/links.liquid
@@ -1,9 +1,7 @@
{%- comment %} dns-prefetch {% endcomment %}
<link rel="dns-prefetch" href="https://cdn.jsdelivr.net">

{%- comment %} canonical link {% endcomment %}
<link rel="canonical" href="{{ schema_surl }}">

{%- comment %} canonical link {% endcomment -%}
{%- if prev -%}
<link rel="prev" href="{{ prev.url | absolute_url }}">
{%- endif -%}
Expand All @@ -12,21 +10,17 @@
<link rel="next" href="{{ next.url | absolute_url }}">
{%- endif -%}

{% comment %} theme {% endcomment %}
<link rel="stylesheet" href="{{ base }}/assets/css/theme{% if site.debug.dist != false %}.min{% endif %}.css">

{%- if custom_scss.size > 0 -%}
<style>{{ custom_scss | scssify | strip_newlines }}</style>
{%- endif -%}
<link rel="canonical" href="{{ schema_surl }}">

{% comment %} favicon icon {% endcomment %}
{%- comment %} favicon icon {% endcomment -%}
<link rel="icon" type="image/svg+xml" href="{{ site.baseurl }}/assets/images/favicon.svg">
{% comment %} alternate {% endcomment %}
{%- comment %} alternate {% endcomment -%}
<link rel="icon" type="image/png" href="{{ site.baseurl }}/assets/images/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="{{ site.baseurl }}/assets/images/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="{{ site.baseurl }}/assets/images/favicon-96x96.png" sizes="96x96">
{% comment %} safari {% endcomment %}
<link rel="mask-icon" href="{{ site.baseurl }}/assets/images/favicon.svg" color="#2980b9">

{% comment %} apple-touch-icon {% endcomment %}
{%- comment %} safari {% endcomment -%}
<link rel="mask-icon" href="{{ site.baseurl }}/assets/images/favicon.svg" color="{{ theme_color }}">

{%- comment %} apple-touch-icon {% endcomment -%}
<link rel="apple-touch-icon" href="{{ site.baseurl }}/assets/images/apple-touch-icon-300x300.jpg">
10 changes: 10 additions & 0 deletions _includes/common/mermaid.liquid
@@ -0,0 +1,10 @@
{%- if content contains '<code class="language-mermaid">' -%}
{%- if site.mermaid.custom -%}
<script src="{{ site.mermaid.custom }}"></script>
{%- else -%}
<script src="{{ base }}/assets/js/mermaid.min.js"></script>
{%- endif %}
<script>
mermaid.initialize({% if site.mermaid.initialize %}{{ site.mermaid.initialize | jsonify }}{% else %}{}{% endif %});
</script>
{%- endif %}
12 changes: 12 additions & 0 deletions _includes/common/meta.liquid
@@ -0,0 +1,12 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, user-scalable=no">
<meta name="description" content="{{ description }}">
<meta name="revised" content="{{ docs.build_revision }}">
<meta name="author" content="{{ author }}">
<meta name="generator" content="{{ generator }} v{{ version }}">

{%- for meta in site.meta -%}
<meta name="{{ meta.first }}" content="{{ meta.last }}">
{%- endfor -%}

<meta name="theme-color" content="{{ theme_color }}">
8 changes: 8 additions & 0 deletions _includes/common/opengraph.liquid
@@ -0,0 +1,8 @@
<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ description }}">
<meta property="og:locale" content="{{ lang }}">
<meta property="og:url" content="{{ schema_surl }}">
<meta property="og:type" content="article">
<meta property="article:author" content="{{ author }}">
<meta property="article:published_time" content="{{ schema_date }}">
<meta property="article:modified_time" content="{{ schema_modi }}">
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
{%- include reset/workdir.liquid workdir=page.dir -%}
{%- include common/rest/workdir.liquid workdir=page.dir -%}

{% comment %} prev and next {% endcomment %}
{%- assign index = 0 -%}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,31 +1,32 @@
{%- comment %} variables {% endcomment -%}
{%- assign version = theme_alias | split: "@" | last -%}
{%- assign docs = site.github -%}
{%- assign rest = docs.public_repositories | where: "html_url", docs.repository_url | first -%}

{%- assign rest_created_at = rest.created_at | default: site.time -%}
{%- assign rest_updated_at = rest.updated_at | default: site.time -%}

{%- comment %} defaults {% endcomment -%}
{%- assign direction = site.direction | default: "auto" -%}
{%- assign lang = site.lang | default: "en" -%}
{%- assign author = docs.owner.name | default: docs.owner_name -%}

{%- capture generator -%}
{%- if site.remote_theme -%}
{{- theme_alias | split: "@" | first -}}
{%- else -%}
{{- theme_alias | split: "@" | first | split: "/" | last -}}
{%- endif -%}
{%- endcapture -%}

{%- comment %} schema {% endcomment -%}
{%- assign schema_date = page.date | default: rest_created_at | date_to_xmlschema -%}
{%- assign schema_modi = site.time | date_to_xmlschema -%}
{%- assign schema_surl = page.url | absolute_url | xml_escape -%}

{% comment %} custom {% endcomment %}
{%- capture custom_scss -%}
{%- include assets/custom.scss -%} {{- site.scss -}}
{%- endcapture -%}

{%- capture custom_script -%}
{%- include assets/custom.js -%} {{- site.script -}}
{%- endcapture -%}

{% comment %} debug {% endcomment %}
{%- if site.debug -%}
{%- assign base = site.baseurl -%}
{%- else -%}
{%- assign base = "https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@" | append: version -%}
{%- assign base = "https://cdn.jsdelivr.net/gh/" | append: theme_alias -%}
{%- endif -%}
File renamed without changes.
File renamed without changes.
Expand Up @@ -9,10 +9,3 @@
}
};
</script>
<script src="{{ base }}/assets/js/jquery.min.js"></script>

{%- if custom_script.size > 0 -%}
<script>{{ custom_script }}</script>
{%- endif -%}

<script src="{{ base }}/assets/js/theme{% if site.debug.dist != false %}.min{% endif %}.js"></script>
File renamed without changes.
6 changes: 6 additions & 0 deletions _includes/common/twitter_cards.liquid
@@ -0,0 +1,6 @@
<meta name="twitter:title" content="{{ title }}">
<meta name="twitter:description" content="{{ description }}">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@{{ author }}">
<meta name="twitter:url" content="{{ schema_surl }}">
<meta name="twitter:creator" content="@{{ generator }} v{{ version }}">
15 changes: 0 additions & 15 deletions _includes/extend/list.liquid

This file was deleted.

Empty file removed _includes/extra/footer.html
Empty file.
Empty file removed _includes/extra/head.html
Empty file.
11 changes: 1 addition & 10 deletions _includes/list.liquid
@@ -1,10 +1 @@
{%- include reset/site_pages.liquid -%}
{%- include reset/workdir.liquid workdir=page.dir -%}

{%- for item in workdir_files %}
- [{{ item.title | default: item.name }}]({{ item.url | relative_url }})
{%- endfor -%}

{%- if include.all -%}
{%- for workdir in workdir_dirs %}{% include extend/list.liquid %}{% endfor -%}
{%- endif -%}
{%- include common/core/list.liquid -%}

0 comments on commit 0de2127

Please sign in to comment.