Skip to content

Commit

Permalink
feat: add documentation for Terraform and Web.dev and remove old GitH…
Browse files Browse the repository at this point in the history
…ub documenation.
  • Loading branch information
brpaz committed Jun 14, 2022
1 parent 6f29b1b commit 6ddfbbe
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 35 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ The following documentation sites are included by default in this extension:
- Eslint
- FluxCD
- Gatsby
- GitHub (**Not working as it seems GitHub stopped using Algolia Docsearch**)
- GitLab
- GORM
- Grafana
Expand All @@ -49,6 +48,7 @@ The following documentation sites are included by default in this extension:
- Supabase
- Symfony
- Tailwind
- Terraform
- Typescript
- Vercel
- Vite
Expand All @@ -59,6 +59,7 @@ The following documentation sites are included by default in this extension:
- Vuex
- Vue-Router
- Webpack
- Web.dev


## Requirements
Expand Down
33 changes: 23 additions & 10 deletions data/docsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,6 @@
"algolia_api_key": "8bca76b0664b04581dc9f9854e844a90",
"url": "https://docs.helm.sh/docs"
},
"github": {
"name": "GitHub",
"description": "GitHub is where over 73 million developers shape the future of software, together.",
"icon": "images/docs/github.png",
"algolia_index": "github-docs-dotcom-en",
"algolia_application_id": "ZI5KPY1HBE",
"algolia_api_key": "685df617246c3a10abba589b4599288f",
"url": "https://docs.github.com"
},
"directus": {
"name": "Directus",
"description": "Directus is an open-source Headless CMS with the flexibility and power of a Data API",
Expand Down Expand Up @@ -379,7 +370,7 @@
"icon": "images/docs/vercel.png",
"algolia_index": "knowledge_production",
"algolia_application_id": "NNTAHQI9C5",
"algolia_api_key": "ac5d89f9877f9fb09dbdc9a010cca761",
"algolia_api_key": "35b6e34b44ca4bcf530d0c4198f58fd8",
"url": "https://vercel.com/",
"facet_filters": []
},
Expand Down Expand Up @@ -459,5 +450,27 @@
"facet_filters": [
"version:current"
]
},
"terraform": {
"name": "Terraform",
"description": "Terraform codifies cloud APIs into declarative configuration files.",
"icon": "images/docs/terraform.png",
"algolia_index": "product_TERRAFORM",
"algolia_application_id": "YY0FFNI7MF",
"algolia_api_key": "49e670100103ee846816a4b1a577004e",
"url": "https://www.terraform.io/docs",
"facet_filters": []
},
"webdev": {
"name": "Web.dev",
"description": "Take advantage of the latest modern technologies to build amazing web experiences for everyone.",
"icon": "images/docs/webdev.png",
"algolia_index": "prod_web_dev",
"algolia_application_id": "2JPAZHQ6K7",
"algolia_api_key": "ac32acde5503ed0ab18332e0592e9919",
"url": "https://web.dev/",
"facet_filters": [
"locales:en"
]
}
}
1 change: 1 addition & 0 deletions docsearch/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def search_in_docset(self, docset, query):
try:
results = self.searcher.search(docset, query)
except Exception as e:
logger.error(e)
return RenderResultListAction([
ExtensionResultItem(
icon='images/icon.png',
Expand Down
2 changes: 1 addition & 1 deletion docsearch/listeners/query_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def on_event(self, event, extension):
term = " ".join(query_parts[1:])
return extension.search_in_docset(docset, term)

return extension.show_docsets_list(event, query)
return extension.list_docsets(event, query)
3 changes: 2 additions & 1 deletion docsearch/mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .default import DefaultMapper # noqa: F401
from .github import GitHubMapper # noqa: F401
from .prisma import PrismaMapper # noqa: F401
from .vercel import VercelMapper # noqa: F401
from .terraform import TerraformMapper # noqa: F401
from .webdev import WebDevMapper # noqa: F401
5 changes: 5 additions & 0 deletions docsearch/mapper/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@


class DefaultMapper():

def get_type(self):
return "default"

def map(self, docset, hit):

print(hit)
title, description = self.map_description(hit)

if not description:
Expand Down
4 changes: 4 additions & 0 deletions docsearch/mapper/prisma.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

class PrismaMapper(DefaultMapper):
""" Mapper for Algolia Docsearch response for Prisma documentation """

def get_type(self):
return 'prisma'

def map(self, docset, hit):
"""
Map function converts an item returned from the Algolia DocSearch to the format to be rendered in Ulauncher
Expand Down
15 changes: 10 additions & 5 deletions docsearch/mapper/github.py → docsearch/mapper/terraform.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from .default import DefaultMapper


class GitHubMapper(DefaultMapper):
""" Mapper for the GitHub documentation """
class TerraformMapper(DefaultMapper):
""" Mapper for Terraform response """

def get_type(self):
return 'terraform'

def map(self, docset, hit):
"""
Map function converts an item returned from the Algolia DocSearch to the format to be rendered in Ulauncher
"""
title = hit["heading"]
description = hit["breadcrumbs"]
url = hit["url"]
title = hit["page_title"]
description = " -> ".join(hit["headings"])

url = "{}/{}".format(docset["url"], hit["objectID"])

return {
'url': url,
Expand Down
4 changes: 4 additions & 0 deletions docsearch/mapper/vercel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

class VercelMapper(DefaultMapper):
""" Mapper for the Vercel documentation """

def get_type(self):
return 'vercel'

def map(self, docset, hit):
"""
Map function converts an item returned from the Algolia DocSearch to the format to be rendered in Ulauncher
Expand Down
29 changes: 29 additions & 0 deletions docsearch/mapper/webdev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from .default import DefaultMapper

import re


class WebDevMapper(DefaultMapper):
""" Mapper for Terraform response """

def get_type(self):
return 'webdev'

def map(self, docset, hit):
"""
Map function converts an item returned from the Algolia DocSearch to the format to be rendered in Ulauncher
"""
title = hit["_highlightResult"]["title"]["value"]

url = "{}{}".format(docset["url"], hit["url"])

return {
'url': url,
'title': self.remove_html(title),
'icon': docset['icon'],
'category': url
}

def remove_html(self, text):
regex = re.compile(r'<[^>]+>')
return regex.sub('', text)
21 changes: 11 additions & 10 deletions docsearch/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
import logging
from docsearch.mapper import DefaultMapper, GitHubMapper, VercelMapper, PrismaMapper
from docsearch.mapper import DefaultMapper, VercelMapper, PrismaMapper, TerraformMapper, WebDevMapper
from algoliasearch.search_client import SearchClient
from algoliasearch.exceptions import AlgoliaException

Expand All @@ -29,6 +29,12 @@ def __init__(self):

self.load_default_docsets()
self.load_user_docsets()
self.results_mappers = [
VercelMapper(),
TerraformMapper(),
PrismaMapper(),
WebDevMapper()
]

def load_default_docsets(self):
""" Loads default docsets into memory """
Expand Down Expand Up @@ -101,7 +107,7 @@ def search(self, docset_key, term):
try:
search_results = index.search(
term, self.get_search_request_options_for_docset(docset))
print(search_results)

if not search_results['hits']:
return []

Expand All @@ -114,14 +120,9 @@ def get_results_mapper(self, docset_key):
"""
Returns the mapper object that will map the specified docset data into the format required by the extension
"""
if docset_key == "prisma":
return PrismaMapper()

if docset_key == "github":
return GitHubMapper()

if docset_key == "vercel":
return VercelMapper()
for mapper in self.results_mappers:
if mapper.get_type() == docset_key:
return mapper

return DefaultMapper()

Expand Down
Binary file added images/docs/terraform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/docs/webdev.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,6 @@
"default_value": "docs:helm",
"icon": "images/docs/helm.png"
},
{
"id": "kw_github",
"type": "keyword",
"name": "GitHub Documentation",
"default_value": "docs:github",
"icon": "images/docs/github.png"
},
{
"id": "kw_directus",
"type": "keyword",
Expand Down Expand Up @@ -335,6 +328,20 @@
"name": "Symfony Documentation",
"default_value": "docs:symfony",
"icon": "images/docs/symfony.png"
},
{
"id": "kw_terraform",
"type": "keyword",
"name": "Terraform Documentation",
"default_value": "docs:terraform",
"icon": "images/docs/terraform.png"
},
{
"id": "kw_webdev",
"type": "keyword",
"name": "Web.dev Documentation",
"default_value": "docs:webdev",
"icon": "images/docs/webdev.png"
}
]
}

0 comments on commit 6ddfbbe

Please sign in to comment.