Skip to content

Commit b415604

Browse files
authored
Merge pull request #70 from ByteInternet/add_date_variables
2 parents 99a4565 + d1de9dc commit b415604

File tree

10 files changed

+161
-4
lines changed

10 files changed

+161
-4
lines changed

.github/workflows/deploy.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ jobs:
1414
runs-on: ubuntu-latest
1515
container: quay.io/hypernode/deploy:3-php8.1-node18
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
# Declares the repository safe and not under dubious ownership.
21+
- name: Add repository to git safe directories
22+
run: git config --global --add safe.directory $GITHUB_WORKSPACE
1823
- uses: actions/cache@v2
1924
with:
2025
path: /tmp/composer-cache

docs/_static/css/general.css

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_static/css/main.css

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_static/scss/general.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ p {
1515
}
1616
}
1717

18+
span, p, div {
19+
color: #404040;
20+
}
21+
1822
a {
1923
text-decoration: none;
2024
}
@@ -806,6 +810,31 @@ li.wy-breadcrumbs-aside a {
806810

807811
/* header end */
808812

813+
/* article meta */
814+
.article-meta {
815+
display: inline-block;
816+
position: relative;
817+
top: 30px;
818+
font-size: 11px;
819+
font-weight: 600;
820+
opacity: 0.35;
821+
822+
&--updated {
823+
opacity: 0.5;
824+
825+
&::after {
826+
content: "";
827+
padding-left: 5px;
828+
}
829+
}
830+
831+
@media (max-width: $breakpoint-mobile) {
832+
font-size: 12px;
833+
}
834+
}
835+
836+
/* article meta end */
837+
809838
/* footer */
810839
.edit {
811840
text-align: center;

docs/_templates/layout.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,22 @@
222222
{%- else %}
223223
<div class="rst-content">
224224
{%- endif %}
225-
<div role="main" class="document main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
225+
<div role="main" class="document main-content" itemscope="itemscope" itemtype="https://schema.org/Article">
226226
{%- block document %}
227+
{%- if updated_at %}
228+
<div class="article-meta article-meta--updated" itemprop="dateModified">Updated {{ updated_at }}</div>
229+
{%- endif %}
230+
{%- if created_at %}
231+
<div class="article-meta" itemprop="dateCreated">Created {{ created_at }}</div>
232+
{%- endif %}
227233
<div itemprop="articleBody">
228234
{% block body %}{% endblock %}
229235
</div>
230236
{%- if self.comments()|trim %}
231237
<div class="articleComments">
232238
{%- block comments %}{% endblock %}
233239
</div>
234-
{%- endif%}
240+
{%- endif %}
235241
</div>
236242
{%- endblock %}
237243
{% include "footer.html" %}

docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66
import os
7+
import sys
78

89
# -- Path setup --------------------------------------------------------------
910

@@ -14,12 +15,13 @@
1415
# import os
1516
# import sys
1617
# sys.path.insert(0, os.path.abspath('.'))
18+
sys.path.append(os.path.abspath("../"))
1719

1820

1921
# -- Project information -----------------------------------------------------
2022

2123
project = "Docs"
22-
copyright = "2022, Hypernode"
24+
copyright = "2023, Hypernode"
2325
author = "Hypernode"
2426

2527
# The full version, including alpha/beta/rc tags
@@ -41,6 +43,7 @@
4143
"myst_parser",
4244
"sphinx_copybutton",
4345
"notfound.extension",
46+
"hypernode.sphinx.extensions.updated_at",
4447
]
4548

4649
# Add any paths that contain templates here, relative to this directory.

hypernode/sphinx/__init__.py

Whitespace-only changes.

hypernode/sphinx/extensions/__init__.py

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os.path
2+
from datetime import datetime
3+
from pathlib import Path
4+
5+
import git
6+
from git.exc import GitCommandError
7+
from sphinx import errors
8+
from sphinx.application import Sphinx
9+
10+
11+
class PageContextHandler:
12+
def __init__(self) -> None:
13+
self.git = git.Git(os.path.realpath(os.path.dirname(__file__) + "../../"))
14+
15+
def execute(self, app: Sphinx, pagename: str, templatename, context, doctree):
16+
page_path = Path(app.confdir) / (pagename + ".md")
17+
if not os.path.exists(page_path):
18+
return
19+
20+
try:
21+
log = self.git.log(
22+
"--pretty=format:%aI", "--reverse", page_path
23+
).splitlines()
24+
if not log:
25+
return
26+
27+
created = log[0]
28+
updated = log[-1]
29+
except GitCommandError as exc:
30+
raise errors.ExtensionError(
31+
"Failed to fetch git history for {}. Exception was: {}".format(
32+
page_path, exc
33+
)
34+
)
35+
36+
if created:
37+
context["created_at"] = datetime.fromisoformat(created).strftime(
38+
app.config.created_at_fmt
39+
)
40+
41+
if updated:
42+
context["updated_at"] = datetime.fromisoformat(updated).strftime(
43+
app.config.updated_at_fmt
44+
)
45+
46+
47+
def setup(app: Sphinx):
48+
page_context_handler = PageContextHandler()
49+
app.add_config_value("updated_at_fmt", "%b %d, %Y", "html")
50+
app.add_config_value("created_at_fmt", "%b %d, %Y", "html")
51+
app.connect("html-page-context", page_context_handler.execute)
52+
53+
return {
54+
"version": "0.1",
55+
"parallel_read_safe": True,
56+
"parallel_write_safe": True,
57+
}

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mdformat-myst==0.1.5
99
mdformat-frontmatter==0.4.1
1010
sphinx-notfound-page==0.8.3
1111
sphinx-sitemap==2.4.0
12+
GitPython==3.1.30
1213

1314
# hypernode/ requirements
1415
beautifulsoup4==4.11.1

0 commit comments

Comments
 (0)