Skip to content

Commit b703a59

Browse files
committed
Implementation of the 'version' field for added/updated/removed
1 parent b3f46a8 commit b703a59

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

web/src/pages/reference/[func].astro

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33
import { getCollection } from 'astro:content';
44
import { getFunctionInfo, parseFunctionSyntaxes, getFixedStaticOOPClass } from '@src/utils/functions';
5-
import { renderInlineMarkdown, getSeeAlsoLinksForItem } from '@src/utils/general';
5+
import { renderInlineMarkdown, getSeeAlsoLinksForItem, extractVersion, isVersionLE } from '@src/utils/general';
66
import fs from "fs";
77
import path from "path";
88
import { Code } from '@astrojs/starlight/components';
9+
import { MTA_CURRENT_VERSION } from '@src/content.constants';
910
1011
import NoteBox from '@src/components/NoteBox.astro';
1112
import type { NotesType } from '@src/utils/types';
@@ -80,6 +81,33 @@ const needsChecking = metaArray.find(m => m.needs_checking)?.needs_checking ?? u
8081
let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
8182
---
8283

84+
<style>
85+
.added-updated-description-box {
86+
display: flex;
87+
flex-direction: column;
88+
background-color: var(--sl-color-bg-nav);
89+
border-radius: 10px;
90+
}
91+
92+
.added-updated-description-box-header {
93+
padding: 0.5rem 1.0rem;
94+
color: var(--sl-color-text);
95+
background-color: var(--sl-color-gray-5);
96+
border-radius: 10px 10px 0 0;
97+
}
98+
99+
.added-updated-description-box.removed-box .added-updated-description-box-header {
100+
background-color: var(--color-type-client-background-high);
101+
color: #f85c50;
102+
font-weight: bold;
103+
}
104+
105+
.added-updated-description-box-body {
106+
margin: 0;
107+
padding: 1rem 1rem;
108+
}
109+
</style>
110+
83111
<div class={"show-type-badge-" + funcType}>
84112
<StarlightPage frontmatter={{
85113
template: 'doc',
@@ -100,7 +128,71 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
100128
)}
101129

102130
<!-- Description -->
103-
<ItemDescription description={funcInfo.description} incomplete={funcInfo.incomplete} />
131+
{funcInfo.version ? (() => {
132+
const CURRENT = MTA_CURRENT_VERSION.full;
133+
134+
const addedVersionRaw = funcInfo.version.added || "";
135+
const updatedVersionRaw = funcInfo.version.updated || "";
136+
const removedVersionRaw = funcInfo.version.removed || "";
137+
138+
const addedVersion = extractVersion(addedVersionRaw);
139+
const updatedVersion = extractVersion(updatedVersionRaw);
140+
141+
const showAdded = !!addedVersion && isVersionLE(CURRENT, addedVersion);
142+
const showUpdated = !!updatedVersion && isVersionLE(CURRENT, updatedVersion);
143+
const showRemoved = !!removedVersionRaw;
144+
145+
// Jeśli nie ma nic do pokazania
146+
if (!showRemoved && !showAdded && !showUpdated) {
147+
return (
148+
<ItemDescription
149+
description={funcInfo.description}
150+
incomplete={funcInfo.incomplete}
151+
/>
152+
);
153+
}
154+
155+
return (
156+
<div
157+
class={
158+
"added-updated-description-box" +
159+
(showRemoved ? " removed-box" : "")
160+
}
161+
>
162+
<div class="added-updated-description-box-header">
163+
<p>
164+
{showRemoved ? (
165+
<>
166+
<strong>Before</strong> {removedVersionRaw}
167+
</>
168+
) : (
169+
<>
170+
{showUpdated && (
171+
<strong>Updated in {updatedVersionRaw}</strong>
172+
)}
173+
{showUpdated && showAdded && ' | '}
174+
{showAdded && (
175+
<strong>Added in {addedVersionRaw}</strong>
176+
)}
177+
</>
178+
)}
179+
</p>
180+
</div>
181+
182+
<div class="added-updated-description-box-body">
183+
<ItemDescription
184+
description={funcInfo.description}
185+
incomplete={funcInfo.incomplete}
186+
/>
187+
</div>
188+
</div>
189+
);
190+
})() : (
191+
<ItemDescription
192+
description={funcInfo.description}
193+
incomplete={funcInfo.incomplete}
194+
/>
195+
)}
104196

105197
<!-- Notes -->
106198
{notesContent.length > 0 && (

web/src/utils/functions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export type FunctionInfo = {
3636
preview_images?: string[];
3737
oop?: OOPInfo;
3838
notes?: NotesType;
39+
version?: VersionInfo
40+
};
41+
42+
type VersionInfo = {
43+
added?: string;
44+
updated?: string;
45+
removed?: string;
3946
};
4047

4148
type FunctionsByCategory = {

web/src/utils/general.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,19 @@ export function getUnfinishedPages(pageType: 'functions' | 'events'): string[] {
235235
// Sort alphabetically
236236
unfinishedPages.sort((a, b) => a.localeCompare(b));
237237
return unfinishedPages;
238+
}
239+
240+
export function extractVersion(versionString: string): string | null {
241+
const match = versionString?.match(/^(\d+\.\d+\.\d+)/);
242+
return match ? match[1] : null;
243+
}
244+
245+
export function isVersionLE(v: string, ref: string): boolean {
246+
console.log(v, ref);
247+
const toNums = (str: string) => str.split('.').map(n => parseInt(n, 10));
248+
const [a1, a2, a3] = toNums(v);
249+
const [b1, b2, b3] = toNums(ref);
250+
if (a1 !== b1) return a1 < b1;
251+
if (a2 !== b2) return a2 < b2;
252+
return a3 <= b3;
238253
}

0 commit comments

Comments
 (0)