Skip to content
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

replaced ajax for compatibility with jQuery slim #781

Closed
wants to merge 1 commit into from

Conversation

VincentTam
Copy link
Contributor

@VincentTam VincentTam commented Feb 9, 2021

Edited: I prefer merging #782

Goal

To resolve #766

Background

Brief evolution history of the part of code concerned for Staticman integration over the past year:

  1. I ported @mmistakes's code in #440 and #444 for Staticman integration (in response to #115).
    if (typeof jQuery == 'undefined') {
    document.write('<script src="{{ site.baseurl }}/js/jquery-1.11.2.min.js"></scr' + 'ipt>');
    }
  2. I moved the JS code in Staticman integration from the Jekyll-HTML template file into a JS file in #521, so that the JS code is found under a more logical location.
  3. The jQuery imported in item 1 was replaced by its slim version at 5991966#diff-e9c677c6d71b6acd8eb0963e0e2a9bd997a86240a3711c2d391c42d18eb12c32.

Description

The ajax method used by jQuery can be replaced by the fetch method, which belongs to standard JS. In this way, the problem would be gone.

Testing

To properly test this PR, you need a working Staticman API instance. I've inactivated mine @staticmanlab due to Staticman's maintainer's advice to move away from any public API instances in the comments in eduardoboucas/staticman#337. For a Staticman API instance setup guide, you may see, for example, what I've written in #775, or https://github.com/pacollins/hugo-future-imperfect-slim/wiki/staticman.yml, which are inspired by Jan Hajek's article about Staticman v3.

  1. I've merged the sm3slim branch into the gh-pages branch for my fork of this theme:

    VincentTam/beautiful-jekyll@e37a4fd...VincentTam:bccdcafb.

    P.S. I had made a careless mistake in the endpoint site config variable while merging the recent development into my gh-pages branch. I corrected that at bccdcaf.

  2. Make sure that you've correctly filled in the theme-specific site config. Here's the one used in this test.

    # To use Staticman comments, uncomment the following section. You may leave the reCaptcha
    # section commented if you aren't using reCaptcha for spam protection. 
    # Using Staticman requires advanced knowledge, please consult 
    # https://github.com/eduardoboucas/staticman/ and https://staticman.net/ for further 
    # instructions. For any support with staticman please direct questions to staticman and 
    # not to BeautifulJekyll.
    staticman:
      repository : vincenttam/beautiful-jekyll # GitHub username/repository eg. "daattali/beautiful-jekyll"
      branch     : gh-pages # If you're not using `master` branch, then you also need to update the `branch` parameter in `staticman.yml`
      endpoint   : https://secretman3.herokuapp.com/v3/entry/github/ # URL of your deployment, with a trailing slash eg. "https://<your-api>/v3/entry/github/"
    #  reCaptcha:   # (optional, set these parameters in `staticman.yml` as well) 
    #    siteKey  : # You need to apply for a site key on Google
    #    secret   : # Encrypt your password by going to https://<your-own-api>/v3/encrypt/<your-site-secret>
  3. I sent a sample message through my online form on my testing site : https://git.io/bjsm18.

    Screenshot from 2021-02-09 13-42-12

    fields value
    fields[message] new post method
    fields[name Vincent Tam
    fields[email] xxxx@live.hk
    fields[url] https://vincentkltam.gitlab.io
    options[origin] https://vincenttam.github.io/beautiful-jekyll/2020-02-28-test-markdown/
    options[slug] test-markdown
  4. I observed a success message. My Staticman API's (secretman3 d0τ herokuapp d0t com) response:

    {
      "success":true,
      "fields":{
        "message":"new post method",
        "name":"Vincent Tam",
        "email":"4980f828b9588a712cc2013ac10fd13a",
        "url":"https://vincentkltam.gitlab.io",
        "hidden":"",
        "date":"2021-02-09T12:41:42.498Z"
      }
    }
  5. Successful PR: New comment by Vincent Tam VincentTam/beautiful-jekyll#35

P.S. I made error in the endpoint variable at VincentTam@f90ee57#diff-ecec67b0e1d7e17a83587c6d27b6baaaa133f42482b07bd3685c77f34b62d883R183. That enabled me to view the displayed error message after merging the sm3slim branch at 36e8bca before correct that variable at the following commit.

VincentTam added a commit to VincentTam/beautiful-jekyll that referenced this pull request Feb 12, 2021
@VincentTam VincentTam closed this Feb 23, 2021
@VincentTam
Copy link
Contributor Author

Closed this in favor of my newer PR created in response to the discussions with the author of linked issue.

@daattali
Copy link
Owner

Thanks Vincent. I'm swamped with work on other projects but will come back to this, I appreciate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$.Ajax not available in staticman.js
2 participants