pacollins / hugo-future-imperfect-slim

Multilingual Blogging Theme for Hugo | Check the Wiki for Documentation
https://themes.gohugo.io/hugo-future-imperfect-slim/
Other
303 stars 194 forks source link

Vanilla Staticman JS & HTML reorganization #245

Closed VincentTam closed 3 years ago

VincentTam commented 3 years ago

Description

  1. HTML reorganization:

    <article>
    <div class="post">
    </div>
    <div class="comments-container">
        <article class="comment" data-reply-thread="{{ $threadID }}">
        </article>
        <article class="comment">
            <article class="comment comment-reply" data-reply-thread="{{ $threadID }}">
            </article>
        </article>
    </div>
    </article>

    In my original PR for Staticman's nested comment support #69, I attempted to stored the post's $threadID with a hidden <span>—that's not the HTML5 way. I wish I knew the use of data- attributes earilier.

    https://github.com/pacollins/hugo-future-imperfect-slim/blob/118943abc5e94ff633a930bf0deaf628fb834459/layouts/post/staticman.html#L72-L83

    Each comment is wrapped by an <article> tag with class name comment and id received from the data file. Each comment reply is nested inside a main comment. I've added the class comments-container to the <div> for JS event delegation (for details, see next point). I don't touch the commented TODO introduced in #154 as I don't know much about the look yet—with the fixed JavaScript, the retrieval of reply target info should be OK.

    I changed the tag name surrounding the Hugo code for Disqus from <article> to <div>.

    I observed that the styles are controlled by the post class in the CSS, so changing the tag name to article should be no impact on the styles.

    The quotes for HTML syntax in layout/_defaults/comments.html are unified to single quotes. I left the double quotes in the Hugo code untouched.

  2. assets/js/staticman.js in Vanilla JS

Motivation and Context

It's motivated by the goal to replace jQuery with Vanilla in https://github.com/pacollins/hugo-future-imperfect-slim/issues/231#issuecomment-794723933. This resolves #242 and resolves #243.

Screenshots (if appropriate):

[You can use Windows+Shift+S or Control+Command+Shift+4 to add a screenshot to your clipboard and then paste it here.]

Example

Checklist:

Critique

The JS code is repetitive. From an OO point of view, directly changing the state of the HTML element should give more concise JS code, and the l10n of button texts can be stored in CSS files. I'm not sure if {{ i18n ... }} can be called in assets/css/*.css. Even though that's possible, Hugo experts might prefer putting UI text in the Go-HTML template layout/**/*.html.

https://github.com/pacollins/hugo-future-imperfect-slim/blob/21d42da01277a9d42730b92b060990cda658c681/assets/js/staticman.js#L66-L78

pacollins commented 3 years ago

Haven't forgotten. Should have more free time in the coming weeks!

pacollins commented 3 years ago

Initial review looks great - all of your comments seem to be good and logical. I will start a full review this evening.

pacollins commented 3 years ago

Looking at #178 again I came across fancyapps/fancybox#2581 - Looks like a Vanilla JS version of Fancybox should be ready soon.

VincentTam commented 3 years ago

If this is true (and the only thing), then I don't feel that is necessary for this PR. Unless I am misunderstanding the problem, I don't see a way to reduce the redundancy.

Agreed and thank you for your thoughts. The "critique" is just like the antithesis and synthesis combined.

With the use of custom data- attributes in HTML, a more "OO-friendly" approach would be:

The last two points would involve playing with the strings "success" and "failed" in JavaScript. That wouldn't simplify the code. More lines would be added—IMHO, my current "redundant" approach is more readable to amateurs.