Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
547aaab
Added Staticman HTML code without CSS
VincentTam Dec 18, 2018
15b1564
[Bug fix]: Added missing Spanish UI string
VincentTam Dec 18, 2018
969c4fa
Merge branch 'es-fix' into staticman3
VincentTam Dec 18, 2018
2c7a85e
Staticman i18n
VincentTam Dec 18, 2018
d44709c
Try porting Minimal Mistakes's CSS
VincentTam Dec 18, 2018
9666cba
File path refactored
VincentTam Dec 18, 2018
fb69227
Fixed CSS alignment
VincentTam Dec 18, 2018
1be3757
i18n for Staticman's button and notifications
VincentTam Dec 18, 2018
0a3c5e0
Use sample reCAPTCHA config
VincentTam Dec 18, 2018
c72951b
Fixed mistaken class names
VincentTam Dec 18, 2018
c463eb4
Bug fix to improve comment submission
VincentTam Dec 19, 2018
081e8f9
Forgotten to clear textarea as well
VincentTam Dec 19, 2018
37c7cf1
Fixed overlapping comments
VincentTam Dec 19, 2018
0c7b2f6
Merge branch 'master' into staticman3
VincentTam Jul 23, 2019
7ce8f0a
Implement branch 'VincentTam-staticman3' of https://github.com/victor…
VincentTam Jul 24, 2019
83e5f27
Modified theme config template
VincentTam Jul 25, 2019
cd18ce0
Fixed missing CSS rules for Staticman
VincentTam Jul 25, 2019
c3416a5
Fixed indentation for reCAPTHCA
VincentTam Jul 25, 2019
91f7cf6
Merge branch 'master' into staticman3
VincentTam Jul 25, 2019
1adf556
WIP porting Huginn's Staticman Integration
VincentTam Aug 2, 2019
da9d9b3
Staticman integration UI improvement
VincentTam Aug 2, 2019
996bcd3
Added back missing Staticman params to avoid 500 error
VincentTam Aug 2, 2019
9dbd2f6
Merge branch 'master' into staticman3
VincentTam Aug 2, 2019
1b22f51
Updated README to provide Staticman setup guide
VincentTam Aug 2, 2019
8b1e782
Updated theme.toml to include Staticman
VincentTam Aug 2, 2019
5023436
Fixed typo in Staticman JS
VincentTam Aug 3, 2019
7f6fe78
Hide redudant code
VincentTam Aug 3, 2019
2f51757
Removed non-standard attributes in textarea
VincentTam Aug 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,89 @@ Set `googleAnalytics` in `config.toml` to activate Hugo's [internal Google Analy

Set `disqusshortname` in `config.toml` to activate Hugo's [internal Disqus template](https://gohugo.io/templates/internal/#disqus).

## Staticman

Procedures to start using Staticman:

1. Add Staticman bot/app, depending on your Git service provider.
- GitHub: choose either one of the following method
+ GitHub App: refer to issue
[https://github.com/eduardoboucas/staticman/issues/243](https://github.com/eduardoboucas/staticman/issues/243)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staticmanapp and https://api.staticman.net/v2 no logner work, as reported in eduardoboucas/staticman#306.

for detailed procedures.
+ GitHub bot: invite
**[@staticmanlab](https://github.com/staticmanlab)** as a collaborator
to your repository (by going to your repository's **Settings** page,
navigating to the **Collaborators** tab.

![add staticmanlab on GitHub](https://user-images.githubusercontent.com/5748535/62385579-c5fc3a80-b555-11e9-9a87-a71e00022d13.png)

Then help **[@staticmanlab](https://github.com/staticmanlab)**
accept the invitation by going to

https://staticman3.herokuapp.com/v3/connect/github/<username>/<repo-name>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staticman's documentation only covers v2, so there's a need to give a self-contained setup guide.


![help staticmanlab accept invitation](https://user-images.githubusercontent.com/5748535/62385576-c563a400-b555-11e9-988b-d6c43226ca53.png)

Now, **[@staticmanlab](https://github.com/staticmanlab)** has been
invited to your repository.

![staticmanlab invited to GitHub repo](https://user-images.githubusercontent.com/5748535/62385578-c5fc3a80-b555-11e9-80ca-f687930a0917.png)

- GitLab: Add the GitLab user associated with your Staticman API endpoint
(e.g. **[@staticmanlab](https://github.com/staticmanlab)** as a
"**developer**" for your project by going to **Settings → Members → Invite
member**.

There's *no* invitation acceptance mechanism on GitLab. The invited
member enjoys the privileges once the invitation is sent. Therefore,
there's *no* need to hit `/connect`.

- Framagit: Since Framagit is a fork of GitLab, the overall setup is similar
to that on GitLab. (Note that the Framagit bot is named as
**[@statimcanlab1](https://framagit.org/staticmanlab1)**.)

![@staticmanlab1 invited to Framagit repo](https://user-images.githubusercontent.com/5748535/62385580-c5fc3a80-b555-11e9-94b4-277cfccc32d7.png)

2. Fill in the site config file `config.toml` with reference to the instructions
in the comments.

Framagit users may choose `gitlab` for `gitProvider` in `config.toml`.

In case of empty `endpoint`, the public Framagit instance will be used.

| instance | `endpoint` |
| --- | --- |
| official production | `https://api.staticman.net` |
| GitLab | `https://staticman3.herokuapp.com` |
| Framagit | `https://staticman-frama.herokuapp.com` |

3. Proceed to the **root-level** repo config file `staticman.yml`. Note that
the name and path of this file *can't* be changed.

The parameter `moderation` is for comment moderation, and it defaults to
`true`, so each new comment is created as a pull/merge request. If it is
switched to `false`, then Staticman will directly commit against the
configured `branch`.

If you are working on GitLab/Framagit and you have set `moderation: false`,
depending on your `branch`, you might need the following steps.

- protected branch (e.g. `master`): Go to **Settings → Repository →
Protected Branches** and permit the GitLab bot to push against that
branch.
- unprotected branch (GitHub's default): *no* measures needed

4. (Optional, GitHub only) To prevent old inactive branches (representing
approved comments) from piling up, you may set up a webhook according to
[Staticman's documenation](https://staticman.net/docs/webhooks). Make sure to
input the **Payload URL** according to your chosen `endpoint`. For example, the
default `endpoint` is `https://staticman3.herokuapp.com`, so the corresponding
**Payload URL** should be `https://staticman3.herokuapp.com/v1/webhook`.

5. (Optional, but recommended) To stop spam bots, it's suggested to enable
[reCAPTCHA](https://developers.google.com/recaptcha/docs/display). You may
refer to the site config file for details.

## Custom css
You can add custom css files by placing them under `assets/` and adding the path to the file to `customCSS` in `config.toml`.

Expand Down
98 changes: 98 additions & 0 deletions assets/js/staticman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
(function ($) {
$('.page__comments-form').submit(function () {
var form = this;

$(form).addClass('disabled');
$('button[type="submit"]:enabled').addClass('hidden'); // hide "submit"
$('button[type="submit"]:disabled').removeClass('hidden'); // show "submitted"

var endpoint = '{{ .endpoint | default "https://staticman-frama.herokuapp.com" }}';
var gitProvider = '{{ .gitprovider }}';
var repo = '{{ .repo }}';
var branch = '{{ .branch }}';

$.ajax({
type: $(this).attr('method'),
url: [endpoint, 'v3/entry', gitProvider, repo, branch, 'comments'].join('/'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated POST request URL in JS code to prevent abuses by spam bots through scraping the generated HTML source code.

data: $(this).serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
showAlert('success');
setTimeout(function(){ clearForm() }, 3000); // display success message for 3s
$(form).disabled = false;
},
error: function (err) {
console.log(err);
showAlert('failed');
$(form).disabled = false;
}
});

return false;
});

function showAlert(msg) {
if (msg == 'success') {
$('.page__comments .submit-success').removeClass('hidden'); // show submit success message
$('.page__comments .submit-failed').addClass('hidden'); // hide submit failed message
} else {
$('.page__comments .submit-success').addClass('hidden'); // hide submit success message
$('.page__comments .submit-failed').removeClass('hidden'); // show submit failed message
}
$('button[type="submit"]:enabled').removeClass('hidden'); // show "submit"
$('button[type="submit"]:disabled').addClass('hidden'); // hide "submitted"
}

function clearForm() {
resetReplyTarget();
$('.page__comments input')
.filter(function() {
return this.name.match(/^fields\[.*\]$/);
})
.val(''); // empty all text & hidden fields
$('.page__comments textarea').val(''); // empty text area
$('.page__comments .submit-success').addClass('hidden'); // hide submission status
$('.page__comments .submit-failed').addClass('hidden'); // hide submission status
}

function resetReplyTarget() {
$('.page__comments .reply-notice .reply-name').text(''); // reset reply target
$('.page__comments .reply-notice img').remove(); // remove reply avatar
$('.page__comments .reply-notice a').remove(); // remove '×' button
$('.page__comments .reply-notice').addClass('hidden'); // hide reply target display
$('.page__comments input[name="fields[replyThread]"]').val('');
$('.page__comments input[name="fields[replyID]"]').val('');
$('.page__comments input[name="fields[replyName]"]').val('');
}

// record reply target when "reply to this comment" is pressed
$('.page__comments .comment').on('click', '.reply-btn', function (evt){
resetReplyTarget();
var cmt = $(evt.delegateTarget);
$('.page__comments input[name="fields[replyThread]"]').val(this.title);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you find my approach of storing the _id of a comment's eldest ancestor in the title attribute of an <a> tag not satisfying, I can change the this.title to replyThread, where var replyThread = cmt.find('.someClassName').

$('.page__comments input[name="fields[replyID]"]').val(cmt.attr('id'));
authorTag = cmt.find('.comment__author');
replyName = authorTag.find('span[itemprop="name"]').text();
$('.page__comments input[name="fields[replyName]"]').val(replyName);

// display reply target avatar and name
$('.page__comments .reply-notice').removeClass('hidden');
$('.page__comments .reply-name').text(replyName);
avatarTag = cmt.find('.comment__avatar');
// use clone to avoid removal of avatar in comments by resetReplyTarget()
$('.page__comments .reply-arrow').after(avatarTag.clone());
// add button for removing reply target (static method would give error msg)
closeBtn = $("<a class='close-btn'></a>");
$('.page__comments .reply-notice').append(closeBtn);
});

// handle removal of reply target when '×' is pressed
$('.page__comments .reply-notice').on('click', 'a.close-btn', function(){
resetReplyTarget();
});

// clear form when reset button is clicked
$('.page__comments input[type="reset"]').click(function (){
clearForm();
});
})(jQuery);
95 changes: 95 additions & 0 deletions assets/sass/_staticman.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.page__comments
/* HTML form */
.page__comments-form
margin-top: 1rem
&.disabled
input, button, textarea, label
pointer-events: none
cursor: not-allowed
filter: alpha(opacity = 65)
box-shadow: none
opacity: 0.65

.form-group
margin: 0.6rem 0 0.6rem 0
textarea
width: 100%
textarea, input
padding: 0.5rem
border: 1px solid $secondary
background: $background
color: $body-color
border-radius: 4px

.reply-notice
.reply-arrow
vertical-align: middle
.comment__avatar
display: inline-block
float: none
width: 2rem
height: 2rem
margin: 0 .6rem
vertical-align: text-bottom
border-radius: 50%
.close-btn
margin: 0 .6rem
&:after
content: '\2716'

.required
font-weight: bold

button
border-radius: 4px
background: $secondary
border: 1px solid $secondary
padding: 0.5rem
margin-right: 0.6rem

/* Static comments */
$avatar__size: 5rem
$avatar__sep: 3rem
$reply__indent: 2rem
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change the values here. Since I'm not a web designer, I haven't considered the mobile loading issue.


.comment
margin: 1rem 0 1rem 0
float: left
width: 100%
clear: both

.comment__avatar-wrapper
float: left
width: $avatar__size
height: $avatar__size
margin-right: $avatar__sep
.comment__avatar
width: 100%
height: 100%
border-radius: 50%

.comment__content-wrapper
float: right
width: calc(100% - #{$avatar__size} - #{$avatar__sep} - 1px)
border-bottom: 1px solid $secondary
.comment__author
margin-bottom: 0.3rem
.comment__content
margin: 0.5rem 0 0.5rem 0
.comment__reply-button
margin-top: 0.6rem
margin-bottom: 0.6rem

&.reply
margin-left: 2rem
width: calc(100% - #{$reply__indent} - 1px)

span[itemprop="name"]
&::after
font-family: 'Font Awesome 5 Free'
content: "\f064"
display: inline-block
padding-left: .5rem
padding-right: .5rem
vertical-align: middle
font-weight: 900
3 changes: 3 additions & 0 deletions assets/sass/style.sass
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ $nunito-font-path: '{{ "fonts/NunitoSans" | absURL }}'
@import "fontawesome-import"
@import "base"
@import "{{ $themeStyle }}-style"
{{ if .Site.Params.staticman }}
@import "staticman"
{{ end }}
11 changes: 11 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ DefaultContentLanguage = "en" # Default language fo
[params.projects]
useTwoColumns = false # Use a layout with two columns instead of three

# [Params.staticman]
# endpoint = "" # URL of your own API deployment (without trailing slash), default: "https://staticman-frama.herokuapp.com"
# gitProvider = "gitlab" # either "github" or "gitlab"
# repo = "user/repo" # your GitHub/GitLab repository
# branch = "master" # branch on which you want to receive comments

# # # If you use reCAPTCHA v2, you must also set these parameters in staticman.yml
# # [Params.staticman.reCaptcha]
# # siteKey = "" # Use your OWN site key, you need to apply for one on Google
# # secret = "" # ENCRYPT your password by going to https://<staticman-endpoint>/v3/encrypt/<your-site-secret>

# Share buttons on blog post pages
[params.share]
twitter = true
Expand Down
Loading