A .NET Core 3.1 Azure Function to post a comment to a GitHub Pages Jekyll blog by automatically creating a pull request in the blog repository.
Phil Haack has described using JavaScript and an Azure Function to support comments on his Jekyll blog. His Azure Function is forked from an Azure function by Damien Guard - this Azure Function updates it to .NET Core 3.1, tidies up a bit and adds dependency injection.
Borrowed from Phil Haack's repository:
- Create an Azure Portal account.
- Fork this repository.
- Create an Azure Function
- [optional] Set up your function to deploy from GitHub. Point it to your fork of this repository.
- Set up the following App Settings for your Azure Function App.
Setting | Value |
---|---|
PullRequestRepository | owner/name of the repository that houses your Jekyll site for pull requests to be created against. For example, agileobjects/blog will post to https://github.com/agileobjects/blog |
GitHubToken | A GitHub personal access token with access to edit your target repository. |
CommentFallbackCommitEmail | The email address to use for GitHub commits and PR's if the form does not supply one. |
The CommentWebsiteUrl
setting has been removed from this version of the function - you can use
CORS
to restrict which website(s) can post comments to your function.
Use an HTML form or AJAX call to post the following data to the function URL:
Name | Value |
---|---|
postId | A unique identifier for the post on which the comment is being made. |
name | The commenter's name. |
message | The comment. |
[optional] The commenter's email address. | |
avatar | [optional] The URL of the commenter's avatar image. |
url | [optional] A URL to which the commenter's name and avatar will link on the posted comment. |
The function will respond with one of the following:
Status | Reason |
---|---|
200 | Comment posted successfully. |
500 | Something unexpected went wrong. |
400 | A piece of required information was either missing, or invalid. A collection of new-line-separated error messages is returned to say what. |
A successful posting creates a pull request in the configured GitHub repository with the comment in
a YAML file. Completing the pull request commits the comment's
file to the repository's _data
folder, adding it to the collection of comments belonging to the
relevant blog, to be rendered by Jekyll.