Skip to content

Commit

Permalink
Use github release description instead of md files
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofandrin committed Feb 8, 2025
1 parent f5aaeb8 commit 45857a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
12 changes: 5 additions & 7 deletions src/app/(general)/release-notes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ import type { Metadata } from "next"
import MarkdownContent from "@/components/common/MarkdownContent"
import { extractMarkdownMetaData } from "@/utils/helpers"

import { getReleaseNotes } from "@/utils/server/github"

export const metadata: Metadata = {
title: "Release Notes - exifoo",
description: "Latest changes of the exifoo desktop app."
}

export default function ReleaseNotes() {
const importAllFiles = (r: any) => r.keys().map(r)
const markdownFiles = importAllFiles(require.context("../../../content/release-notes", false, /\.md$/))
.sort()
.reverse()
export default async function ReleaseNotes() {
const markdownFiles: string[] = await getReleaseNotes()

return (
<div className="flex flex-col items-center">
<div className="mt-24 w-full px-7 sm:mt-32 sm:max-w-screen-xl">
<h1 className="pb-6 font-logo text-3xl font-bold tracking-tight text-neutral-800 sm:text-4xl">
Release Notes
</h1>
{markdownFiles.map((release: { default: string }, i: number) => {
let content = release.default
{markdownFiles.map((content: string, i: number) => {
const [rawMetaData, metaData] = extractMarkdownMetaData(content)
content = content.replace(rawMetaData[0], "")
const date = metaData.date
Expand Down
Empty file removed src/content/release-notes/.gitkeep
Empty file.
7 changes: 0 additions & 7 deletions src/content/release-notes/2025-01-20_v0.1.0.md

This file was deleted.

9 changes: 0 additions & 9 deletions src/content/release-notes/2025-02-08_v0.1.1.md

This file was deleted.

5 changes: 3 additions & 2 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export function extractMarkdownMetaData(text: string): Array<any> {

if (rawMetaData!) {
// rawMeta[1] are the stuff between "---"
keyValues = rawMetaData[1].split("\n")
keyValues = rawMetaData[1].split("\r\n")

// which returns a list of key values: ["key1: value", "key2: value"]
keyValues.forEach((keyValue) => {
// split each keyValue to keys and values
const [key, value] = keyValue.split(":")
let [key, value] = keyValue.split(":")
key = key.trim()
metaData[key] = value.trim()
})
}
Expand Down
17 changes: 15 additions & 2 deletions src/utils/server/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "server-only"

const API_BASE_URL = "https://api.github.com"

async function request(method: string, url: string): Promise<Record<any, any>> {
async function request(method: string, url: string): Promise<Record<any, any> | Record<any, any>[]> {
const headers = {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.GH_TOKEN}`,
Expand All @@ -16,7 +16,7 @@ async function request(method: string, url: string): Promise<Record<any, any>> {

export async function getMacOSDownloadURL(arch: string): Promise<string> {
const latestReleaseUrl = "/repos/codeofandrin/exifoo-releases/releases/latest"
const data = await request("GET", latestReleaseUrl)
const data: Record<any, any> = await request("GET", latestReleaseUrl)
const releaseAssets: Record<string, any>[] = data.assets

let downloadUrl
Expand All @@ -31,3 +31,16 @@ export async function getMacOSDownloadURL(arch: string): Promise<string> {

return downloadUrl
}

export async function getReleaseNotes(): Promise<string[]> {
const releasesUrl = "/repos/codeofandrin/exifoo-releases/releases"
const data = (await request("GET", releasesUrl)) as Record<string, any>[]

let releaseNotes: string[] = []
for (let i = 0; i < data.length; i++) {
const release = data[i]
releaseNotes.push(release.body)
}

return releaseNotes
}

0 comments on commit 45857a4

Please sign in to comment.