Fully automated bluesky commenting system on mkdocs
Background¶
This post is basically continuation of the previous post and outlines the steps taken to achieve the following flow:
Once the steps of previous post are completed, basically following additional steps will ensure that a new post will trigger creation of a bluesky post which in turn will enable bluesky comments on the post on the site.
Create environment secrets¶
-
Open Site Repo.
Visit your site repo on github.
-
Add Passwrod Secret.
In
Name
field enterBSKY_APP_PWD
and inValue
field enter the application password created on bluesky site and clickSave
-
Add Handle Secret
In
Name
field enterBSKY_HANDLE
and inValue
field enter the email address used to register the bluesky account to be used for commenting system.
Python Script¶
Assumptions
- Python script assumes that
social plugin
of material for mkdocs is enabled. It relies on the social ocards created using that plugin. If it is not enabled, it will need to be enabled inmkdocs.yml
as per the instructions on material for mkdocs guidance. - It also assumes that the frontmatter explicitly specifies the
slug
for the post. - Python script does not check if
bsky: true
is present in metadata and assumes that every new blog post will warrant a creation of bluesky post.
In the root of the site repository create a new file named post_deploy.py
and paste the following code:
./post_deploy.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
- Please make sure
atproto
package is included inrequirements.txt
. - This can be changed to any other integer. Basically, it is ensuring that only posts created in last 5 days are checked. If changed to 10, it will check for last 10 day and so on.
- Ensure the spelling
BSKY_HANDLE
is same here and in environment secret created in previous step. - Ensure the spelling
BSKY_APP_PWD
is same here and in environment secret created in previous step. - Make sure the path is reflecting the location of
.md
files where commenting is to be enabled.
The script does the following:
- Runs through all
.md
files indocs/posts
- Calls
get_yaml_frontmatter
function which checks if the path is a file or a directory. - As it is a directory, it cycles through all files with
.md
extension and for each file extracts the yaml frontmatter. - It then passes it to the function
process_file_yaml
which in turn checks if the post is within last 5 days and if so it checks theslug
for the post and creates the url from it and checks if a bluesky post exists for that url. - If the bluesky post does not exist for this post, it creates one and if it does then it skips this file and returns to
get_yaml_frontmatter
and cycle continues until all.md
files have been checked.
Update requirements.txt¶
In order for the python script to work, following packages must be included on the requirements.txt
:
Github Action¶
Finally, add the following at the end of the githib action that builds the mkdocs site. You can check how it's done on my repo here
This passes the environment secrets and variables to the script before calling it to be run.