mirror of
https://github.com/jonasrafa/kunkun-ext-on-this-day.git
synced 2025-04-03 17:56:43 +00:00
init
This commit is contained in:
commit
884c5cc0ee
177
.gitignore
vendored
Normal file
177
.gitignore
vendored
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
|
||||||
|
logs
|
||||||
|
_.log
|
||||||
|
npm-debug.log_
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Caches
|
||||||
|
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
|
||||||
|
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
|
||||||
|
pids
|
||||||
|
_.pid
|
||||||
|
_.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
|
||||||
|
.temp
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# IntelliJ based IDEs
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Finder (MacOS) folder config
|
||||||
|
.DS_Store
|
||||||
|
extensions_support/
|
||||||
|
|
57
CHANGELOG.md
Normal file
57
CHANGELOG.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# template-ext-worker
|
||||||
|
|
||||||
|
## 0.0.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.5
|
||||||
|
|
||||||
|
## 0.0.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.4
|
||||||
|
|
||||||
|
## 0.0.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.2
|
||||||
|
|
||||||
|
## 0.0.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.1
|
||||||
|
|
||||||
|
## 0.0.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.0
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.53
|
||||||
|
|
||||||
|
## 0.0.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.48
|
||||||
|
|
||||||
|
## 0.0.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.47
|
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# What Happened Today
|
||||||
|
|
||||||
|
This is an extension that allows you to explore historical events that occurred on any day in history. Whether you’re curious about today’s historical significance or want to learn about a specific date, this extension makes it easy to discover important moments from the past.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- **Today’s Events**: By default, view significant historical events for today’s date from past years.
|
||||||
|
- **Learn More**: Click on a historical event to view related Wikipedia articles for deeper insights.
|
||||||
|
|
||||||
|
- **Ported from Raycast**: This is a port of the "What Happened Today" extension from Raycast. You can find the original extension here: [https://www.raycast.com/nikhil_tiwari/what-happened-today](https://www.raycast.com/nikhil_tiwari/what-happened-today)
|
30
build.ts
Normal file
30
build.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { watch } from "fs"
|
||||||
|
import { join } from "path"
|
||||||
|
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
|
||||||
|
import { $ } from "bun"
|
||||||
|
|
||||||
|
const entrypoints = ["./src/index.ts"]
|
||||||
|
|
||||||
|
async function build() {
|
||||||
|
try {
|
||||||
|
for (const entrypoint of entrypoints) {
|
||||||
|
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
|
||||||
|
}
|
||||||
|
if (Bun.argv.includes("dev")) {
|
||||||
|
await refreshTemplateWorkerCommand()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const srcDir = join(import.meta.dir, "src")
|
||||||
|
|
||||||
|
await build()
|
||||||
|
|
||||||
|
if (Bun.argv.includes("dev")) {
|
||||||
|
console.log(`Watching ${srcDir} for changes...`)
|
||||||
|
watch(srcDir, { recursive: true }, async (event, filename) => {
|
||||||
|
await build()
|
||||||
|
})
|
||||||
|
}
|
3514
package-lock.json
generated
Normal file
3514
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
Normal file
49
package.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schema.kunkun.sh",
|
||||||
|
"name": "kunkun-ext-on-this-day",
|
||||||
|
"version": "0.0.10",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"kunkun": {
|
||||||
|
"name": "What Happened Today",
|
||||||
|
"shortDescription": "Get the historical events that happened on this day.",
|
||||||
|
"longDescription": "Discover historical events, notable birthdays, and milestones on any date.",
|
||||||
|
"identifier": "kunkun-ext-on-this-day",
|
||||||
|
"permissions": [
|
||||||
|
"fetch:all",
|
||||||
|
"clipboard:read-all"
|
||||||
|
],
|
||||||
|
"demoImages": [],
|
||||||
|
"icon": {
|
||||||
|
"type": "iconify",
|
||||||
|
"value": "material-symbols:history-rounded"
|
||||||
|
},
|
||||||
|
"customUiCmds": [],
|
||||||
|
"templateUiCmds": [
|
||||||
|
{
|
||||||
|
"name": "This Day In History",
|
||||||
|
"description": "Get the historical events that happened on this day.",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"cmds": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "bun build.ts dev",
|
||||||
|
"build": "bun build.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@kksh/api": "0.1.5",
|
||||||
|
"i18next": "^23.15.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bun": "latest"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "^5.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"./dist",
|
||||||
|
".gitignore"
|
||||||
|
]
|
||||||
|
}
|
2346
pnpm-lock.yaml
generated
Normal file
2346
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
public/screenshot1.jpg
Normal file
BIN
public/screenshot1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 160 KiB |
BIN
public/screenshot2.jpg
Normal file
BIN
public/screenshot2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
5
src/i18n/en.ts
Normal file
5
src/i18n/en.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const en = {
|
||||||
|
welcome: "Welcome to Kunkun"
|
||||||
|
}
|
||||||
|
export default en
|
||||||
|
export type Translation = typeof en
|
20
src/i18n/index.ts
Normal file
20
src/i18n/index.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import i18next from "i18next"
|
||||||
|
import en, { type Translation } from "./en"
|
||||||
|
import zh from "./zh"
|
||||||
|
|
||||||
|
export function setupI18n(language: "en" | "zh" = "en") {
|
||||||
|
i18next.init({
|
||||||
|
resources: {
|
||||||
|
en: {
|
||||||
|
translation: en
|
||||||
|
},
|
||||||
|
zh: {
|
||||||
|
translation: zh
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lng: language, // default language
|
||||||
|
fallbackLng: "en"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const t = (key: keyof Translation, options?: any) => i18next.t(key, options)
|
5
src/i18n/zh.ts
Normal file
5
src/i18n/zh.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import type { Translation } from "./en"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
welcome: "欢迎来到Kunkun"
|
||||||
|
} satisfies Translation
|
153
src/index.ts
Normal file
153
src/index.ts
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
import {
|
||||||
|
expose,
|
||||||
|
Icon,
|
||||||
|
IconEnum,
|
||||||
|
List,
|
||||||
|
Markdown,
|
||||||
|
TemplateUiCommand,
|
||||||
|
ui,
|
||||||
|
} from "@kksh/api/ui/template";
|
||||||
|
import type {
|
||||||
|
ApiResponse,
|
||||||
|
OnThisDayJson,
|
||||||
|
WikipediaOnThisDay,
|
||||||
|
WikipediaPageJson,
|
||||||
|
} from "./types";
|
||||||
|
import type { WikipediaPage } from "./types";
|
||||||
|
|
||||||
|
class OnThisDay extends TemplateUiCommand {
|
||||||
|
private wikipediaPages: WikipediaOnThisDay[] = [];
|
||||||
|
|
||||||
|
detailViewOfOnThisDay(onThisDay: WikipediaOnThisDay, date: Date) {
|
||||||
|
const dateMarkdown =
|
||||||
|
"## " + this.dateGetMonthAndDay(date) + ", " + onThisDay.year.toString();
|
||||||
|
const eventDetails = "### " + onThisDay.eventDescription;
|
||||||
|
const relatedArticlesMarkdown =
|
||||||
|
"### " + `Related Articles (${onThisDay.pages.length.toString()})`;
|
||||||
|
const pageDataMarkdown = onThisDay.pages
|
||||||
|
.map(
|
||||||
|
(page: WikipediaPage) =>
|
||||||
|
`### [${page.title}](${page.pageUrl})
|
||||||
|
\n\n${page.extract}
|
||||||
|
\n\n\n`
|
||||||
|
)
|
||||||
|
.join("\n---\n");
|
||||||
|
|
||||||
|
return ui.render(
|
||||||
|
new Markdown(
|
||||||
|
dateMarkdown +
|
||||||
|
"\n" +
|
||||||
|
eventDetails +
|
||||||
|
"\n" +
|
||||||
|
relatedArticlesMarkdown +
|
||||||
|
"\n" +
|
||||||
|
pageDataMarkdown
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
dateGetMonthAndDay(date: Date) {
|
||||||
|
const monthString = date.toLocaleString("default", { month: "long" });
|
||||||
|
const day = date.getDate();
|
||||||
|
return `${monthString} ${day}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getWikipediaOnThisDay(date: Date): Promise<WikipediaOnThisDay[]> {
|
||||||
|
try {
|
||||||
|
const year = date.getFullYear();
|
||||||
|
let month: string | number = date.getMonth() + 1;
|
||||||
|
let day: string | number = date.getDate();
|
||||||
|
month = month < 10 ? "0" + month : month.toString();
|
||||||
|
day = day < 10 ? "0" + day : day.toString();
|
||||||
|
const response = await fetch(
|
||||||
|
`https://api.wikimedia.org/feed/v1/wikipedia/en/featured/${year}/${month}/${day}`
|
||||||
|
);
|
||||||
|
const data = (await response.json()) as ApiResponse;
|
||||||
|
const onThisDay = data.onthisday;
|
||||||
|
const wikipediaPages: WikipediaOnThisDay[] = onThisDay.map(
|
||||||
|
(item: OnThisDayJson) => {
|
||||||
|
const subpages: WikipediaPage[] = item.pages.map(
|
||||||
|
(subItem: WikipediaPageJson) => ({
|
||||||
|
title: subItem.normalizedtitle,
|
||||||
|
extract: subItem.extract,
|
||||||
|
pageUrl: subItem.content_urls.desktop.page,
|
||||||
|
imageUrl: subItem.thumbnail?.source || "",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
// setIsLoading(false);
|
||||||
|
return {
|
||||||
|
year: item.year,
|
||||||
|
eventDescription: item.text,
|
||||||
|
pages: subpages,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return wikipediaPages;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading Wikipedia stories", error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async load() {
|
||||||
|
const date = new Date();
|
||||||
|
this.wikipediaPages = await this.getWikipediaOnThisDay(date);
|
||||||
|
console.log(this.wikipediaPages);
|
||||||
|
|
||||||
|
if (!this.wikipediaPages) {
|
||||||
|
return ui.render(new Markdown("No data found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ui
|
||||||
|
.setSearchBarPlaceholder("Enter a search term, and press enter to search")
|
||||||
|
.then(() => {
|
||||||
|
return ui.render(
|
||||||
|
new List.List({
|
||||||
|
sections: [
|
||||||
|
new List.Section({
|
||||||
|
title: "On This Day in History",
|
||||||
|
items: this.wikipediaPages.map(
|
||||||
|
(item) =>
|
||||||
|
new List.Item({
|
||||||
|
title: item.eventDescription,
|
||||||
|
value: item.eventDescription,
|
||||||
|
defaultAction: "Show Details",
|
||||||
|
accessories: [
|
||||||
|
new List.ItemAccessory({
|
||||||
|
date: date,
|
||||||
|
text: item.year.toString(),
|
||||||
|
tooltip: "Year",
|
||||||
|
}),
|
||||||
|
// new List.ItemAccessory({
|
||||||
|
// text: "Pages: " + item.pages.length.toString(),
|
||||||
|
// tooltip: "Pages",
|
||||||
|
// }),
|
||||||
|
],
|
||||||
|
icon: new Icon({
|
||||||
|
type: IconEnum.Iconify,
|
||||||
|
value: "mdi:wikipedia",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onListItemSelected(value: string): Promise<void> {
|
||||||
|
const wikipediaPage = this.wikipediaPages.find(
|
||||||
|
(item) => item.eventDescription === value
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!wikipediaPage) {
|
||||||
|
return ui.render(new Markdown("No data found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.detailViewOfOnThisDay(wikipediaPage, new Date());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expose(new OnThisDay());
|
39
src/types.ts
Normal file
39
src/types.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
export interface WikipediaOnThisDay {
|
||||||
|
year: number;
|
||||||
|
pages: WikipediaPage[];
|
||||||
|
eventDescription: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WikipediaPage {
|
||||||
|
title: string;
|
||||||
|
extract: string;
|
||||||
|
pageUrl: string;
|
||||||
|
imageUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON response from the Wikipedia API
|
||||||
|
**/
|
||||||
|
|
||||||
|
export interface WikipediaPageJson {
|
||||||
|
normalizedtitle: string;
|
||||||
|
extract: string;
|
||||||
|
content_urls: {
|
||||||
|
desktop: {
|
||||||
|
page: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
thumbnail: {
|
||||||
|
source: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnThisDayJson {
|
||||||
|
text: string;
|
||||||
|
pages: WikipediaPageJson[];
|
||||||
|
year: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiResponse {
|
||||||
|
onthisday: OnThisDayJson[];
|
||||||
|
}
|
27
tsconfig.json
Normal file
27
tsconfig.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// Enable latest features
|
||||||
|
"lib": [
|
||||||
|
"ESNext",
|
||||||
|
"DOM"
|
||||||
|
],
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"allowJs": true,
|
||||||
|
// Bundler mode
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": false,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"noEmit": true,
|
||||||
|
// Best practices
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
// Some stricter flags (disabled by default)
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"noPropertyAccessFromIndexSignature": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user