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

auto-post to discourse #62

Open
unusualevent opened this issue Feb 2, 2024 · 1 comment
Open

auto-post to discourse #62

unusualevent opened this issue Feb 2, 2024 · 1 comment

Comments

@unusualevent
Copy link

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
Copy link
Author

(yes, this is probably vulnerable to injection)

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

No branches or pull requests

1 participant