From 38827133fa5278116b8523eb785b7400c2e27b7f Mon Sep 17 00:00:00 2001 From: samaradel Date: Thu, 29 Sep 2022 18:20:12 +0200 Subject: [PATCH] Add ETA time --- static/js/custom.js | 13 ++++++ templates/_default/base.html | 1 - templates/blogPage.html | 69 +++++++++++---------------- templates/partials/postCard.html | 80 ++++++++++++++++++-------------- 4 files changed, 85 insertions(+), 78 deletions(-) diff --git a/static/js/custom.js b/static/js/custom.js index 4b1064d48..e7fc72867 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -4,6 +4,19 @@ var hamburgerShown = false; let width = screen.width; var isMobile = width < 1024; +function readingTime() { + let articles = document.querySelectorAll(".article"); + let times = document.querySelectorAll(".time"); + const wpm = 225; + let words; + for (var i = 0; i < articles.length; i++) { + words = articles[i].innerText.trim().split(/\s+/).length; + let time = Math.ceil(words / wpm); + times[i].innerText = `${time} minute read` + } +} +readingTime() + function toggleMenu(button) { if (displayedMenu === button.id.split("-")[0]) { button.className = button.className.replace(" text-gray-800 bg-stone-200 sm:bg-transparent", " text-gray-900"); diff --git a/templates/_default/base.html b/templates/_default/base.html index 6d789147e..ac65b6023 100644 --- a/templates/_default/base.html +++ b/templates/_default/base.html @@ -36,7 +36,6 @@ for (var i = 0, linksLength = links.length; i < linksLength; i++) { if (!internal_hosts.includes(links[i].hostname)) { links[i].target = '_blank'; - console.log(links[i]) } } diff --git a/templates/blogPage.html b/templates/blogPage.html index f7ce34890..a3bab94cb 100644 --- a/templates/blogPage.html +++ b/templates/blogPage.html @@ -2,48 +2,32 @@ {% block content %} {% if page.taxonomies.people %} - {% set people = get_section(path="people/_index.md") %} - {% set pages_str = people.pages | json_encode() | as_str %} - {% if pages_str is containing(page.taxonomies.people[0]) %} - {% set author_path = 'people/' ~ page.taxonomies.people[0] ~ '/index.md' %} - {% set author = get_page(path=author_path) %} - {% endif %} +{% set people = get_section(path="people/_index.md") %} +{% set pages_str = people.pages | json_encode() | as_str %} +{% if pages_str is containing(page.taxonomies.people[0]) %} +{% set author_path = 'people/' ~ page.taxonomies.people[0] ~ '/index.md' %} +{% set author = get_page(path=author_path) %} +{% endif %} {% endif %} {% set split = page.content | split(pat="threefold.io") %} -{% if split | length < 2 %} - {% set content = page.content %} -{% else %} - {% set content = "" %} - {% for part in split %} - {% if part is starting_with("/blog") %} - {% set split_part = part | split(pat='/">') %} - {% set link = split_part[0] %} - {% set link = link | replace(from="/blog/post", to="/blog") %} - {% set link = link | replace(from="_", to="-") %} - {% set rest_part = split_part | slice(start=1) | join(sep='/">') %} - {% set part = link ~ '/">' ~ rest_part %} - {% endif %} - {% if loop.first %} - {% set_global content = part%} - {% else %} - {% set_global content = content ~ "threefold.io" ~ part%} - {% endif %} - {% endfor %} -{% endif %} - - -
+{% if split | length < 2 %} {% set content=page.content %} {% else %} {% set content="" %} {% for part in split %} {% if + part is starting_with("/blog") %} {% set split_part=part | split(pat='/">' ) %} {% set link=split_part[0] %} {% set + link=link | replace(from="/blog/post" , to="/blog" ) %} {% set link=link | replace(from="_" , to="-" ) %} {% set + rest_part=split_part | slice(start=1) | join(sep='/">' ) %} {% set part=link ~ '/">' ~ rest_part %} {% endif %} {% if + loop.first %} {% set_global content=part%} {% else %} {% set_global content=content ~ "threefold.io" ~ part%} {% endif + %} {% endfor %} {% endif %}
-
+

{{ page.title }}

+

{{ page.description }}

@@ -52,9 +36,10 @@
  • - {% if author %} - {% set author_img = get_url(path='/' ~ author.relative_path | replace(from='_', to='-') | replace(from='index.md', to=author.extra.imgPath)) %} - {{author.title}} - {% if author %} + {% if author %} {{ author.title }} - {% endif %} + {% endif %}

    - +

- {% set img_url = get_url(path='/' ~ page.relative_path | replace(from='_', to='-') | replace(from='index.md', to=page.extra.imgPath)) %} + {% set img_url = get_url(path='/' ~ page.relative_path | replace(from='_', to='-') | replace(from='index.md', + to=page.extra.imgPath)) %} {{page.title ~ 'Picture'}} -
{{ content | safe }}
- - +
{{ content | safe }}
-
+
-{% endblock content %} \ No newline at end of file + {% endblock content %} \ No newline at end of file diff --git a/templates/partials/postCard.html b/templates/partials/postCard.html index 0da63c7b9..b9defaab2 100644 --- a/templates/partials/postCard.html +++ b/templates/partials/postCard.html @@ -1,17 +1,19 @@ {% if post.date %} {% if post.taxonomies.people %} - {% set people = get_section(path="people/_index.md") %} - {% set pages_str = people.pages | json_encode() | as_str %} - {% if pages_str is containing(post.taxonomies.people[0]) %} - {% set author_path = 'people/' ~ post.taxonomies.people[0] ~ '/index.md' %} - {% set author = get_page(path=author_path) %} - {% endif %} +{% set people = get_section(path="people/_index.md") %} +{% set pages_str = people.pages | json_encode() | as_str %} +{% if pages_str is containing(post.taxonomies.people[0]) %} +{% set author_path = 'people/' ~ post.taxonomies.people[0] ~ '/index.md' %} +{% set author = get_page(path=author_path) %} +{% set content = get_page(path=author_path) %} +{% endif %} {% endif %}
-
-
-
-
-
    - {% if author %} - {% set author_img = get_url(path='/' ~ author.relative_path | replace(from='_', to='-') | replace(from='index.md', to=author.extra.imgPath)) %} -
  • {{author.title}}
  • - {% endif %} -
-
-
- {% if author %} -

{{ author.title }}

- {% endif %} -

- -

-
-
-
-
+
{% endif %} \ No newline at end of file