this should work with the edge cases. my old one would get choked up processing h2s and make would poop its pants and i'd have to manally rerun my automation. hopefull this fixes it. also i hadded some debugging checks that go off when i send to give a lil info incase it doesn't go through just to help me see whats goin' on better.
looks like the regex is screwing up the codeblock unfortunately
function! Blogpost() " Get the current buffer content let l:buf_content = join(getline(1, '$'), "\n") " Debugging: Show the full content of the buffer echo "Buffer Content:" echo l:buf_content " Try to extract the first heading tag (h1 through h6) let l:title = '' for l:i in range(1, 6) " Loop through heading levels
to
let l:heading = matchstr(l:buf_content, '
\(.*\) ') if l:heading != '' let l:title = substitute(l:heading, '\(.*\) ', '\1', '') break endif endfor " If no heading found, print error if l:title == '' echo "No heading found (to
)." return endif " Debugging: Show extracted title echo "Extracted Title:" echo l:title " Extract content after the first heading let l:content_start = matchend(l:buf_content, '
.* ') let l:content = strpart(l:buf_content, l:content_start) " Debugging: Show the extracted content echo "Extracted Content:" echo l:content " Check if title and content are not empty if l:title == '' || l:content == '' echo "Error: Missing title or content." return endif " Create a dictionary for the JSON payload let l:json_dict = { \ 'title': l:title, \ 'content': l:content \ } " Convert the dictionary to JSON let l:json_payload = json_encode(l:json_dict) " Debugging: Show the JSON payload echo "JSON Payload:" echo l:json_payload " Create a temporary file to hold the JSON payload let l:tmpfile = tempname() call writefile([l:json_payload], l:tmpfile) " Prepare the curl command let l:cmd = 'curl -X POST https://hook.us1.make.com/YOUPUTYOURWEBOOKSECRETHERE -H "Content-Type: application/json" -d @' . shellescape(l:tmpfile) " Run the curl command let l:output = system(l:cmd) " Clean up the temporary file call delete(l:tmpfile) " Show the output or errors echo l:output endfunction " Create a command to run the function command! Blogpost call Blogpost()
No comments:
Post a Comment