-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes opentofu/opentofu#1131: Provide releases page
- Loading branch information
Janos Bonic
committed
Jan 16, 2024
1 parent
c3963f6
commit 1996ec4
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type {PagesFunction} from "@cloudflare/workers-types"; | ||
|
||
interface Env { | ||
} | ||
|
||
export const onRequest: PagesFunction<Env> = async (context) => { | ||
const data = JSON.parse(await fetch("https://api.github.com/repos/opentofu/opentofu/releases")) | ||
|
||
const listItems = data.map(data => { | ||
const li = document.createElement("li") | ||
const a = document.createElement("a") | ||
li.appendChild(a) | ||
a.href = data.name.replace("v", "") | ||
a.innerText = data.name.replace("v", "") | ||
return li.outerHTML | ||
}) | ||
|
||
return new Response('<!DOCTYPE html><html><head></head><body><ul>' + listItems.join() + '</ul></body></html>', { | ||
status: 200, | ||
headers: { | ||
'content-type': 'text/html; charset=utf-8', | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type {PagesFunction} from "@cloudflare/workers-types"; | ||
|
||
interface Env { | ||
} | ||
|
||
export const onRequest: PagesFunction<Env> = async (context) => { | ||
const response = await fetch("https://api.github.com/repos/opentofu/opentofu/releases/tags/v" + encodeURIComponent(context.params.release), {headers: {"User-Agent": "OpenTofu Releases Page"}}) | ||
const data = await response.json() | ||
|
||
const listItems = data.assets.map(asset => `<li><a href="${asset.browser_download_url}">${asset.name}</a></li>`) | ||
|
||
return new Response('<!DOCTYPE html><html><head><title>OpenTofu releases</title></head><body><ul><li><a href="/releases/">../</a></li>' + listItems.join() + '</ul></body></html>', { | ||
status: 200, | ||
headers: { | ||
'content-type': 'text/html; charset=utf-8', | ||
}, | ||
}); | ||
} |