nivenly / website

Apache License 2.0
5 stars 22 forks source link

auto-post to discourse #62

Open unusualevent opened 6 months ago

unusualevent commented 6 months ago

untested snippet for CICD.

this compares the previous sitemap to the one you just generated. If it's different, it posts a discussion to discourse.

# generate site first.
# compare new sitemap to old one.
grep "<loc>" public/sitemap.xml | sort > /tmp/new.txt
curl https://nivenly.org/sitemap.xml | grep "<loc>" | sort > /tmp/old.txt
new_post_url=$(sort /tmp/new.txt /tmp/old.txt | uniq -u)
if [[ ! -z $new_post_url ]]; then
    # need changed filename to grab title
    new_file=$(git diff --name-only HEAD HEAD~1 | grep "content/en/blog")
    title=$(grep "title: " $new_file | head -n 1)
    # https://docs.discourse.org/#tag/Topics/operation/createTopicPostPM
    data='{"title":"'+"$title"+'",'
    data=$data+'"raw":"Discussion about: \"' + "$title"
    data=$data+ ' \" - '
    data=$data+ "$new_post_url"
    data=$data+ '- automatically posted via github action.",'
    data=$data+'"caategory":"Blog Updates"',
    data=$data+'"embed_url":"'+"$new_post_url"+'"}'
    curl -x POST \
    -H "Api-Key: $SECRET_DISCOURSE_KEY" \
    -H "Api-Username: system"
    -d $data https://nivenly.discourse.org/posts.json
fi
unusualevent commented 6 months ago

(yes, this is probably vulnerable to injection)