Skip to content

Commit 4bc0130

Browse files
authored
Merge pull request #726 from processing/deprecation
Handle deprecation notes in reference items
2 parents 1b8b763 + 7d301cf commit 4bc0130

File tree

8 files changed

+41
-5
lines changed

8 files changed

+41
-5
lines changed

src/components/ReferenceDirectoryWithFilter/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMemo, useRef, useState } from "preact/hooks";
33
import { type JSX } from "preact";
44
import { Icon } from "../Icon";
55
import flask from "@src/content/ui/images/icons/flask.svg?raw";
6+
import warning from "@src/content/ui/images/icons/warning.svg?raw";
67

78
type ReferenceDirectoryEntry = ReferenceDocContentItem & {
89
data: {
@@ -43,6 +44,10 @@ const getOneLineDescription = (description: string): string => {
4344
let [oneLineDescription] = description.replace(/\n/g, " ").trim()
4445
.match(firstParagraphRegex) ?? [];
4546

47+
if (!oneLineDescription && description) {
48+
oneLineDescription = description;
49+
}
50+
4651
if(oneLineDescription){
4752
oneLineDescription = oneLineDescription
4853
.replace(/^<p>|<\/p>$/g, "")
@@ -108,6 +113,12 @@ export const ReferenceDirectoryWithFilter = ({
108113
dangerouslySetInnerHTML={{ __html: flask }}
109114
/>
110115
)}
116+
{entry.data.deprecated && (
117+
<div
118+
className="inline-block mr-2 w-[16px] h-[16px] mb-[-2px]"
119+
dangerouslySetInnerHTML={{ __html: warning }}
120+
/>
121+
)}
111122
<span dangerouslySetInnerHTML={{ __html: entry.data.title }} />
112123
</span>
113124
<p

src/content/reference/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const referenceSchema = z.object({
6464
submodule: z.string().optional(),
6565
file: z.string(),
6666
description: z.string().optional(),
67+
deprecated: z.string().optional(),
6768
line: z.number().or(z.string().transform((v) => parseInt(v, 10))),
6869
params: z.array(paramSchema).optional(),
6970
overloads: z.array(z.object({ params: z.array(paramSchema) })).optional(),

src/content/ui/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ calloutTitles:
186186
"Try this!": "Try this!"
187187
Tip: Tip
188188
Note: Note
189+
Warning: Warning
189190
LibrariesLayout:
190191
View All: View All
191192
Featured: Featured
Lines changed: 5 additions & 0 deletions
Loading

src/layouts/ReferenceItemLayout.astro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
import { setJumpToState } from "../globals/state";
2121
import { p5Version } from "../globals/p5-version";
2222
import flask from "@src/content/ui/images/icons/flask.svg?raw";
23+
import warning from "@src/content/ui/images/icons/warning.svg?raw";
2324
2425
const { entry, relatedEntries } = Astro.props;
2526
const currentLocale = getCurrentLocale(Astro.url.pathname);
@@ -106,6 +107,18 @@ const descriptionParts = description.split(
106107
<p>{t('experimentalApi', 'description')}</p>
107108
</div>
108109
)}
110+
{entry.data.deprecated && (
111+
<div class="deprecated">
112+
<h5>
113+
<div
114+
class="inline-block mr-2 w-[20px] h-[20px] mb-[-2px]"
115+
set:html={warning}
116+
/>
117+
{t('calloutTitles', 'Warning')}
118+
</h5>
119+
<p set:html={entry.data.deprecated} />
120+
</div>
121+
)}
109122
{descriptionParts.map((part) => {
110123
if (part.startsWith('<pre')) {
111124
const exampleCode = part

src/scripts/builders/reference.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ const convertToMDX = async (
255255
file: doc.file.replace(/.*p5\.js\/(.*)/, "$1"),
256256
description: doc.description ?? "",
257257
line: doc.line,
258+
deprecated: doc.deprecated,
258259
} as Record<string, unknown>;
259260

260261
// Add specific frontmatter based on the type of doc

styles/global.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pre.code-box,
291291
white-space: break-spaces;
292292
}
293293

294-
.callout, .experimental {
294+
.callout, .experimental, .deprecated {
295295
padding: var(--spacing-sm);
296296
border-radius: 20px;
297297
background-color: var(--bg-magenta-20);
@@ -308,7 +308,7 @@ pre.code-box,
308308
}
309309
}
310310

311-
.experimental {
311+
.experimental, .deprecated {
312312
background-color: var(--bg-yellow);
313313
}
314314

types/parsers.interface.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type ReferenceOverload = {
4949
export type ReferenceOverloads = ReferenceOverload[];
5050

5151
/* Represents the definition of a class within the project, including its properties, methods, and inheritance information. */
52-
export interface ReferenceClassDefinition extends Chainable {
52+
export interface ReferenceClassDefinition extends Chainable, Deprecatable, MaybeBeta {
5353
name: string; // The name of the class.
5454
shortname: string; // A shorter or abbreviated name for the class.
5555
classitems: ReferenceParam[]; // Parameters or properties of the class.
@@ -92,6 +92,10 @@ interface Chainable {
9292
chainable: number;
9393
}
9494

95+
interface Deprecatable {
96+
deprecated?: string; // If this item is deprecated, a description of why.
97+
}
98+
9599
/* Represents the return value of a method or constructor */
96100
interface Return {
97101
description: string;
@@ -103,7 +107,7 @@ interface MaybeBeta {
103107
}
104108

105109
/* Represents a method within a class */
106-
export interface ReferenceClassItemMethod extends BaseClassItem, Chainable, MaybeBeta {
110+
export interface ReferenceClassItemMethod extends BaseClassItem, Chainable, MaybeBeta, Deprecatable {
107111
params?: ReferenceParam[];
108112
return?: Return;
109113
example?: string[];
@@ -119,7 +123,7 @@ interface MethodOverload {
119123
}
120124

121125
/* Represents a property within a class */
122-
export interface ReferenceClassItemProperty extends BaseClassItem {
126+
export interface ReferenceClassItemProperty extends BaseClassItem, Deprecatable {
123127
type: string;
124128
}
125129

0 commit comments

Comments
 (0)