Skip to content

Commit

Permalink
add elevator
Browse files Browse the repository at this point in the history
  • Loading branch information
flxzt committed Mar 9, 2024
1 parent fc7d643 commit 9fbf846
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ Enable math rendering inline with `$` and blocks with `$$` pairs through [Temml]
temml = true
```

Enable the elevator:

```toml
[extra]
elevator = true
```

Social buttons can be added. The available icon names are the file names without `.svg` in `static/social_icons/`.

```toml
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ favicon = "/images/favicon.svg"
theme = "auto" # either `auto`, `dark` or `light`
use_cdn = false
temml = true
elevator = true

menu = [
{ name = "/posts", url = "/posts", weight = 1 },
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"elevator.js": "^1.0.1"
},
"scripts": {
"post-update": "npm install --prefix ./static/ --only=production"
}
}
19 changes: 19 additions & 0 deletions sass/parts/_misc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ aside {
clear: both;
}

.elevator-button {
color: var(--primary-color);
background-color: var(--accent-bg);
width: 2rem;
height: 2rem;
bottom: 30px;
right: 30px;
text-align: center;
border: 1px solid var(--border-color);
border-radius: 4px;
position: fixed;
visibility: hidden;
transition: opacity 1s;
}

.elevator-button:hover {
cursor:pointer;
}

@media all and (max-width:719px) {
aside {
// force to go full width for mobile
Expand Down
Binary file added static/audio/elevator/ding.mp3
Binary file not shown.
Binary file added static/audio/elevator/music.mp3
Binary file not shown.
14 changes: 14 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Elevator
window.addEventListener('scroll', e => {
const threshold = 300;
document.querySelector('.elevator-button').style.visibility = window.scrollY > threshold ? 'visible' : 'hidden';
document.querySelector('.elevator-button').style.opacity = window.scrollY > threshold ? '1' : '0';
});

window.onload = function () {
var elevator = new Elevator({
element: document.querySelector('.elevator-button'),
mainAudio: '/audio/elevator/music.mp3',
endAudio: '/audio/elevator/ding.mp3'
});
}
18 changes: 18 additions & 0 deletions static/js/temml_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
renderMathInElement(
document.body,
{
delimiters: [
{ left: "$$", right: "$$", display: true },
// Put $ after $$.
{ left: "$", right: "$", display: false },
{ left: "\\(", right: "\\)", display: false },
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
{ left: "\\begin{align}", right: "\\end{align}", display: true },
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
{ left: "\\begin{multline}", right: "\\end{multline}", display: true },
{ left: "\\[", right: "\\]", display: true }
]
}
);
17 changes: 17 additions & 0 deletions static/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/package.json
26 changes: 7 additions & 19 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,16 @@
</small>
</footer>
{% endif %}

{% if config.extra.elevator | default(value=false) %}
<button class="elevator-button"> 🛗 </button>
{% endif %}
</div>
</body>

{% if config.extra.temml | default(value=false) %}
<script>renderMathInElement(
document.body,
{
delimiters: [
{ left: "$$", right: "$$", display: true },
// Put $ after $$.
{left: "$", right: "$", display: false},
{ left: "\\(", right: "\\)", display: false },
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
{ left: "\\begin{align}", right: "\\end{align}", display: true },
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
{ left: "\\begin{multline}", right: "\\end{multline}", display: true },
{ left: "\\[", right: "\\]", display: true }
]
}
);</script>
<script type="text/javascript"
src="{{ get_url(path="/js/temml_config.js") }}">
</script>
{% endif %}

</html>
18 changes: 17 additions & 1 deletion templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
{% endif %}
{% endif %}

{# Elevator #}
{% if config.extra.temml | default(value=false) %}
{% if config.extra.use_cdn | default(value=false) %}
<script type="text/javascript"
src=" https://cdn.jsdelivr.net/npm/elevator.js@1.0.1/elevator.min.js ">
</script>
{% else %}
<script type="text/javascript"
src="{{ get_url(path="/node_modules/elevator.js/elevator.min.js") }}">
</script>
{% endif %}
{% endif %}

{# Font from cdn or local #}
{% if config.extra.use_cdn | default(value=false) %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/roboto@4.5.8/400.css">
Expand Down Expand Up @@ -80,10 +93,13 @@

<link rel="stylesheet" type="text/css" media="screen" href={{ get_url(path="main.css") }} />


{% if config.extra.stylesheets %}
{% for stylesheet in config.extra.stylesheets %}
<link rel="stylesheet" href="{{ get_url(path=stylesheet) }}">
{% endfor %}
{% endif %}

<script type="text/javascript"
src="{{ get_url(path="/js/main.js") }}">
</script>
</head>

0 comments on commit 9fbf846

Please sign in to comment.