Last active
September 3, 2021 05:24
-
-
Save kdmsnr/26775a503d630fc06f2c0050271fc9ed to your computer and use it in GitHub Desktop.
AlfredのワークフローでScrapboxを検索する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Originally created by Yuta Yamamoto <https://github.com/tuki0918/alfred-scrapbox-listview> | |
file = "/tmp/#{ENV['projectId']}-scrapbox.json" | |
if !File.exist?(file) or File.mtime(file) < (Time.now - 3*3600) | |
`/usr/bin/curl -H "Cookie: connect.sid=#{ENV['token']}" -o #{file} -s "https://scrapbox.io/api/pages/#{ENV['projectId']}?limit=1000&sort=accessed"` | |
end | |
q = `echo "{query}" | /usr/local/bin/nkf -w --ic=utf8-mac` | |
q.strip! | |
items = `/bin/cat #{file} | /usr/local/bin/jq -c '[ .pages[] | select(.title | test("#{q}";"i")) |\ | |
{ \ | |
"uid":.id \ | |
,"title":.title \ | |
,"subtitle": ("description: " + (.descriptions | join(" / ")) + "...") \ | |
,"arg":.title | |
} \ | |
]'` | |
print '{"items":' | |
print items.strip | |
print '}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment