Skip to content

Commit df1073d

Browse files
committed
⬆️ Add support for Flask 2.0.x
1 parent 1512cfa commit df1073d

File tree

9 files changed

+53
-22
lines changed

9 files changed

+53
-22
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Klemen Tušar
3+
Copyright (c) 2022 Klemen Tušar
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ flask jsonify
2424

2525
Either press `⌘Y` to Quick Look the result, or press `<enter>` to open it in your web browser.
2626

27-
## Supported Branches
27+
## Changing Branches
2828

29-
Currently the app indexes branch __1.0__ only.
29+
The workflow supports searching the documentation all the active branches, that is `v0.12`, `v1`, `v1.1`, and `v2`.
30+
By default, it searches the `v2` branch. To search branch `v1.1` simply type `v1.1` **anywhere** in your query, like so:
31+
32+
```
33+
flask jsonify v1.1
34+
```
3035

3136
### Note
3237

flask-docs-v1.0.5.alfredworkflow

-779 KB
Binary file not shown.

flask-docs-v1.0.6.alfredworkflow

807 KB
Binary file not shown.

src/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Config(object):
99
# Icon
1010
FLASK_ICON = "icon.png"
1111
GOOGLE_ICON = "google.png"
12+
# supported docs
13+
SUPPORTED_FLASK_VERSIONS = {"2", "1.1", "1", "0.12"}
14+
DEFAULT_FLASK_VERSION = "2"
1215
# Algolia credentials
1316
ALGOLIA_APP_ID = "WODHKE4WZG"
1417
ALGOLIA_SEARCH_ONLY_API_KEY = "7456cdd91ba8d4f87846549697397759"

src/docs.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
log = None
2222

2323

24-
def cache_key(query):
24+
def cache_key(query, version=Config.DEFAULT_FLASK_VERSION):
2525
"""Make filesystem-friendly cache key"""
26-
key = query
26+
key = query + "_" + version
2727
key = key.lower()
2828
key = re.sub(r"[^a-z0-9-_;.]", "-", key)
2929
key = re.sub(r"-+", "-", key)
30-
# log.debug("Cache key : {!r} -> {!r}".format(query, key))
30+
# log.debug("Cache key : {!r} {!r} -> {!r}".format(query, version, key))
3131
return key
3232

3333

@@ -41,9 +41,18 @@ def handle_result(api_dict):
4141
return result
4242

4343

44-
def search(query=None, limit=Config.RESULT_COUNT):
44+
def search(
45+
query=None, version=Config.DEFAULT_FLASK_VERSION, limit=Config.RESULT_COUNT
46+
):
4547
if query:
46-
results = index.search(query, {"page": 0, "hitsPerPage": limit})
48+
results = index.search(
49+
query,
50+
{
51+
"facetFilters": ["version:{}".format(version)],
52+
"page": 0,
53+
"hitsPerPage": limit,
54+
},
55+
)
4756
if results is not None and "hits" in results:
4857
return results["hits"]
4958
return []
@@ -61,6 +70,10 @@ def main(wf):
6170

6271
query = wf.args[0].strip()
6372

73+
# Tag prefix only. Treat as blank query
74+
if query == "v":
75+
query = ""
76+
6477
if not query:
6578
wf.add_item("Search the Flask docs...")
6679
wf.send_feedback()
@@ -69,16 +82,26 @@ def main(wf):
6982
# Parse query into query string and tags
7083
words = query.split(" ")
7184

72-
query = " ".join(words)
85+
query = []
86+
version = Config.DEFAULT_FLASK_VERSION
87+
88+
for word in words:
89+
if word.replace("v", "") in Config.SUPPORTED_FLASK_VERSIONS:
90+
version = word.replace("v", "")
91+
else:
92+
query.append(word)
93+
94+
query = " ".join(query)
7395

74-
log.debug("query : {!r}".format(query))
96+
# log.debug("version: {!r}".format(version))
97+
# log.debug("query: {!r}".format(query))
7598

76-
key = cache_key(query)
99+
key = cache_key(query, version)
77100

78101
results = [
79102
handle_result(result)
80103
for result in wf.cached_data(
81-
key, functools.partial(search, query), max_age=Config.CACHE_MAX_AGE
104+
key, functools.partial(search, query, version), max_age=Config.CACHE_MAX_AGE
82105
)
83106
]
84107

src/info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<key>variablesdontexport</key>
124124
<array/>
125125
<key>version</key>
126-
<string>1.0.5</string>
126+
<string>1.0.6</string>
127127
<key>webaddress</key>
128128
<string>https://github.com/techouse</string>
129129
</dict>

src/requirements.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Alfred-Workflow==1.37.2
2-
algoliasearch==2.0.4
3-
certifi==2019.6.16
4-
chardet==3.0.4
5-
idna==2.8
6-
requests==2.22.0
7-
typing==3.7.4
8-
urllib3==1.26.5
1+
Alfred-Workflow>=1.40.0
2+
algoliasearch>=2.6.1
3+
certifi>=2021.10.8
4+
chardet>=4.0.0
5+
idna>=2.10
6+
requests>=2.26.0
7+
typing>=3.10.0.0
8+
urllib3>=1.26.7

src/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.5
1+
1.0.6

0 commit comments

Comments
 (0)