-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mastodon comments feature. Fixes #157 #158
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing ! Silly question, have you experimented it yet ?
www/assets/css/theme.css
Outdated
* ╰───────────────────────────────────────────────────────────────╯ | ||
**/ | ||
|
||
section#comments #comments-wrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicks, mostly for consistency :
#comments-wrapper
is enough here- empty lines between CSS rules please (much easier to navigate with Vim)
- space after the colon sign please (
:
rather than:
)
www/assets/css/theme.css
Outdated
margin:1.5em 0; | ||
padding:0 var(25px); | ||
} | ||
section#comments .comment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.comment
is enough here and in all following rules
www/layouts/_default/single.html
Outdated
</div> | ||
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript> | ||
<script src="/js/purify.min.js"></script> | ||
<script type="text/javascript"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind putting this script in a separate file, e.g. comments.js
or mastodon-comments.js
please ?
www/assets/css/theme.css
Outdated
* ╭───────────────────────────────────────────────────────────────╮ | ||
* │ Comments │ | ||
* ╰───────────────────────────────────────────────────────────────╯ | ||
**/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be in a separate CSS file, e.g. comments.css
, as it’s only used by single-page articles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that’s pretty good ! It seems to be working really well on my end, the render could be a bit fancier, especially with heavily nested responses, but we’ll address that later, it’s good enough as is.
I do have a few problems with the overall code structure, though. The main one being the huge js script in the middle of layouts/partials/comments
.
www/layouts/partials/comments.html
Outdated
</noscript> | ||
</div> | ||
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript> | ||
<script type="text/javascript"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the code to fetch the comments to a separate layout partial is a step in the right direction, but I would greatly prefer if this was in it’s own js file in ergol/code/comments.js
.
You can use Hugo’s js.Build with a params
dict to pass in values from the front matter to the js script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to pass Hugo variables to a separate js file, thanks for the tip, I will have a look
www/layouts/partials/comments.html
Outdated
href="https://{{ .host }}/@{{ .username }}/{{ .id }}">le post original</a> sur Mastodon.</p> | ||
</noscript> | ||
</div> | ||
<noscript>Vous devez activer Javascript pour voir les commentaires.</noscript> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This noscript
tag is redundant, the one above is more detailed
www/layouts/partials/comments.html
Outdated
if ( | ||
descendants && | ||
Array.isArray(descendants) && | ||
descendants.length > 0 | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be an early return, with a few error messages in case it gets triggered, depending on the context (like no comments yet, fetch failed…)
www/layouts/partials/comments.html
Outdated
) { | ||
commentsWrapper.innerHTML = ""; | ||
|
||
descendants.forEach(function (status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is quite a bit of code needed to properly render a comment, so it could be nice to make it a web component. If it requires too much work on your end, we can leave this as is and I’ll come back to it later, it’s not that big a deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to do it properly, so I will leave it to you if you don't mind.
New commits to separate js code |
It is needed to add params at top of an article to enable comments feature.
Example: