The extensions that were in Toolshed's own repository, a folder each: brreg, dashboard-icons, databricks, docker, github, homebrew, norway, projects, scripts, secrets, wikipedia and yr. Toolshed installs them from here, in Settings → Extensions → From a repository, and the README says how
This commit is contained in:
44 files changed
+7978
-1
No files matched your search
@@ -0,0 +1,133 @@
|
||||
-- Wikipedia: "wiki rust" lists matching articles; Enter shows an article's summary, and Enter
|
||||
-- there opens it. ⌘K opens it or copies its link from either. The last jig opens Wikipedia's
|
||||
-- own search for what was typed.
|
||||
|
||||
-- Wikimedia asks automated clients to say what they are.
|
||||
local agent = "Toolshed-Wikipedia-extension/1.0"
|
||||
|
||||
local encode = toolshed.url_encode
|
||||
|
||||
local escape = toolshed.escape
|
||||
|
||||
local function get(url, max_seconds)
|
||||
return toolshed.json.decode(toolshed.exec({ "curl", "-sSfL", "--max-time", tostring(max_seconds), "-A", agent, url }))
|
||||
end
|
||||
|
||||
local function site(settings)
|
||||
return "https://" .. settings.language .. ".wikipedia.org"
|
||||
end
|
||||
|
||||
local function article_address(data)
|
||||
return "https://" .. data.language .. ".wikipedia.org/wiki/" .. encode(data.key)
|
||||
end
|
||||
|
||||
return toolshed.toolbox {
|
||||
key = "wikipedia",
|
||||
title = "Wikipedia",
|
||||
description = "i18n:toolbox.description",
|
||||
icon = "book-open",
|
||||
tint = "gray",
|
||||
|
||||
settings = {
|
||||
{ key = "language", title = "i18n:setting.language.title", description = "i18n:setting.language.description", type = "choice", default = "en",
|
||||
options = {
|
||||
{ value = "en", title = "English" },
|
||||
{ value = "no", title = "Norsk (bokmål)" },
|
||||
{ value = "nn", title = "Norsk (nynorsk)" },
|
||||
{ value = "sv", title = "Svenska" },
|
||||
{ value = "da", title = "Dansk" },
|
||||
{ value = "de", title = "Deutsch" },
|
||||
{ value = "fr", title = "Français" },
|
||||
{ value = "es", title = "Español" },
|
||||
} },
|
||||
},
|
||||
|
||||
tools = {
|
||||
{
|
||||
key = "search",
|
||||
title = "i18n:tool.search.title",
|
||||
words = { "wiki" },
|
||||
examples = { "wiki rust", "wiki oslo" },
|
||||
keywords = { "wikipedia", "encyclopedia", "leksikon" },
|
||||
-- Wikipedia is asked once typing pauses, not for every letter on the way.
|
||||
debounce = true,
|
||||
|
||||
search = function(rest, settings)
|
||||
if rest == "" then return {} end
|
||||
local jigs = {}
|
||||
-- Offline or slow, the search page is still offered.
|
||||
local ok, found = pcall(get, site(settings) .. "/w/rest.php/v1/search/title?limit=8&q=" .. encode(rest), 1.5)
|
||||
for _, page in ipairs(ok and found.pages or {}) do
|
||||
local thumb = page.thumbnail and page.thumbnail.url
|
||||
table.insert(jigs, {
|
||||
title = page.title,
|
||||
subtitle = page.description,
|
||||
image = thumb and ("https:" .. thumb) or nil,
|
||||
tool = "article",
|
||||
data = { key = page.key, title = page.title, language = settings.language },
|
||||
})
|
||||
end
|
||||
table.insert(jigs, {
|
||||
title = toolshed.t("search-for", { query = rest }),
|
||||
action = "open-search",
|
||||
data = { query = rest, language = settings.language },
|
||||
})
|
||||
return jigs
|
||||
end,
|
||||
|
||||
actions = {
|
||||
{
|
||||
key = "open-search", title = "i18n:action.search.open-search",
|
||||
run = function(ctx)
|
||||
toolshed.open("https://" .. ctx.data.language .. ".wikipedia.org/w/index.php?fulltext=1&search=" .. encode(ctx.data.query))
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "article",
|
||||
title = "i18n:tool.article.title",
|
||||
hidden = true,
|
||||
items = true,
|
||||
|
||||
actions = {
|
||||
{
|
||||
-- The summary is a page with jigs for what to do next: Enter opens the article.
|
||||
key = "summary", title = "i18n:action.article.summary",
|
||||
run = function(ctx)
|
||||
local s = get("https://" .. ctx.data.language .. ".wikipedia.org/api/rest_v1/page/summary/" .. encode(ctx.data.key), 10)
|
||||
local picture = ""
|
||||
if s.thumbnail and s.thumbnail.source then
|
||||
picture = '<img src="' .. escape(s.thumbnail.source) .. '" alt="" style="float:right;max-width:40%;max-height:220px;margin:0 0 12px 16px;border-radius:8px">'
|
||||
end
|
||||
local paragraphs = {}
|
||||
for line in (s.extract or ""):gmatch("[^\n]+") do
|
||||
table.insert(paragraphs, "<p style=\"margin:0 0 10px\">" .. escape(line) .. "</p>")
|
||||
end
|
||||
local page = '<div style="padding:20px 24px;color:var(--text);line-height:1.5;overflow:auto;height:100%;box-sizing:border-box">'
|
||||
.. picture
|
||||
.. '<h2 style="margin:0 0 2px;font-size:20px;font-weight:600">' .. escape(s.title) .. '</h2>'
|
||||
.. '<div style="margin-bottom:14px;color:var(--text-secondary)">' .. escape(s.description) .. '</div>'
|
||||
.. table.concat(paragraphs)
|
||||
.. '</div>'
|
||||
return { html = page, jigs = {
|
||||
{ title = toolshed.t("action.article.open"), icon = "external-link", action = "open", data = ctx.data },
|
||||
{ title = toolshed.t("action.article.copy-link"), icon = "link", action = "copy-link", data = ctx.data },
|
||||
} }
|
||||
end,
|
||||
},
|
||||
{
|
||||
key = "open", title = "i18n:action.article.open", shortcut = "cmd+enter",
|
||||
run = function(ctx) toolshed.open(article_address(ctx.data)) end,
|
||||
},
|
||||
{
|
||||
key = "copy-link", title = "i18n:action.article.copy-link", shortcut = "cmd+shift+c",
|
||||
run = function(ctx)
|
||||
toolshed.clipboard.copy(article_address(ctx.data))
|
||||
return toolshed.t("link-copied")
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
[toolbox.description]
|
||||
other = "Finds Wikipedia articles and shows their summaries"
|
||||
|
||||
[setting.language.title]
|
||||
other = "Language"
|
||||
|
||||
[setting.language.description]
|
||||
other = "Which Wikipedia to search"
|
||||
|
||||
[tool.search.title]
|
||||
other = "Search Wikipedia"
|
||||
|
||||
[search-for]
|
||||
other = "Search Wikipedia for “{{.query}}”"
|
||||
|
||||
[action.search.open-search]
|
||||
other = "Open Search Page"
|
||||
|
||||
[tool.article.title]
|
||||
other = "Wikipedia Article"
|
||||
|
||||
[action.article.summary]
|
||||
other = "Show Summary"
|
||||
|
||||
[action.article.open]
|
||||
other = "Open in Browser"
|
||||
|
||||
[action.article.copy-link]
|
||||
other = "Copy Link"
|
||||
|
||||
[link-copied]
|
||||
other = "Link copied"
|
||||
@@ -0,0 +1,32 @@
|
||||
[toolbox.description]
|
||||
other = "Finner Wikipedia-artikler og viser sammendragene deres"
|
||||
|
||||
[setting.language.title]
|
||||
other = "Språk"
|
||||
|
||||
[setting.language.description]
|
||||
other = "Hvilken Wikipedia det søkes i"
|
||||
|
||||
[tool.search.title]
|
||||
other = "Søk i Wikipedia"
|
||||
|
||||
[search-for]
|
||||
other = "Søk i Wikipedia etter «{{.query}}»"
|
||||
|
||||
[action.search.open-search]
|
||||
other = "Åpne søkesiden"
|
||||
|
||||
[tool.article.title]
|
||||
other = "Wikipedia-artikkel"
|
||||
|
||||
[action.article.summary]
|
||||
other = "Vis sammendrag"
|
||||
|
||||
[action.article.open]
|
||||
other = "Åpne i nettleseren"
|
||||
|
||||
[action.article.copy-link]
|
||||
other = "Kopier lenke"
|
||||
|
||||
[link-copied]
|
||||
other = "Lenke kopiert"
|
||||
Reference in new issue
Block a user