From c820a9e16ba6405b6220e29d4f8e546adce42f16 Mon Sep 17 00:00:00 2001 From: Stefan Kleineikenscheidt Date: Tue, 6 Sep 2022 23:50:11 +0200 Subject: [PATCH] Initial version for #17 --- README.md | 4 +++- src/confluence-quicksearch.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 937b705..76bb806 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,12 @@ Alfred. Just hit type `c ` to search for Confluence. ## Features -- Super simple configuration thanks to the new Workflow User Configuration in Alfred 5. +- Super simple configuration thanks to the new [Workflow User Configuration](https://www.alfredapp.com/alfred-5-whats-new/) in Alfred 5. - Limit to search to single spaces by adding `-s ` to the search terms - Limit to search to content types by adding `-t ` to the search terms ( is a comma-separated list of `page`, `blogpost`, `attachment`, e.g. `page,attachment`) +- Directly edit pages when selecting a search result with `⌘Enter` - Copy Confluence page URL with `⌘C` +- Displays page emojis 🥳 - Authentication via API token diff --git a/src/confluence-quicksearch.py b/src/confluence-quicksearch.py index 7af81c0..26d2739 100644 --- a/src/confluence-quicksearch.py +++ b/src/confluence-quicksearch.py @@ -2,6 +2,7 @@ import ast import base64 import json +import re import requests import sys import urllib @@ -29,13 +30,17 @@ def parseArgs(): args = parser.parse_args() args.textAsString = " ".join(args.text) + args.pathPrefix = "" + if re.search("atlassian.net", args.url) or re.search("jira.com", args.url): + args.pathPrefix = "/wiki" + return args def searchConfluence(args): response = requests.request( "GET", - args.url + '/wiki/rest/api/search', + args.url + args.pathPrefix + '/rest/api/search', headers = { "Accept": "application/json", "Authorization": createAuth(args) @@ -98,7 +103,7 @@ def convertToAlfredItems(searchResults, args): alfredItems.append({ "title": "No search results", "subtitle": "Hit to do a full-text search for '" + args.textAsString + "' in Confluence", - "arg": args.url + "/wiki/search?text=" + urllib.parse.quote(args.textAsString), + "arg": args.url + args.pathPrefix + "/search?text=" + urllib.parse.quote(args.textAsString), "icon": { "path": "./assets/search-for.png" }, @@ -145,7 +150,7 @@ def createSubtitle(result, args): def createUrl(result, args): - return args.url + '/wiki' + result["url"] + return args.url + args.pathPrefix + result["url"] def getIconPath(result, args): @@ -162,7 +167,7 @@ def getMods(result, args): if result["content"]["type"] == "blogpost" or result["content"]["type"] == "page": mod["cmd"] = { "valid": True, - "arg": args.url + '/wiki' + result["content"]["_links"]["editui"], + "arg": args.url + args.pathPrefix + result["content"]["_links"]["editui"], "subtitle": "Open in editor" } @@ -175,7 +180,7 @@ def convertToTextResult(searchResults, args): if len(searchResults) < 1: textResult += "No search results found\n" textResult += " Search Confluence for '" + args.textAsString + "':\n" - textResult += " " + args.url + "/wiki/search?text=" + urllib.parse.quote(args.textAsString) + textResult += " " + args.url + args.pathPrefix + "/search?text=" + urllib.parse.quote(args.textAsString) for result in searchResults: textResult += "· " + createTitle(result, args) + "\n"