@@ -4,6 +4,12 @@ import { indexPlans } from "~/util/plans";
44import { marked } from " marked" ;
55import GlossaryTooltip from " ~/components/GlossaryTooltip.astro" ;
66
7+ const markdown = (content : any ) => {
8+ if (typeof content !== " string" ) return content ;
9+
10+ return marked .parse (content );
11+ };
12+
713type Props = z .infer <typeof props >;
814
915const props = z
@@ -17,30 +23,29 @@ const { id } = props.parse(Astro.props);
1723// TODO: improve product features types
1824const plan = (await indexPlans (id )) as any ;
1925
20- // @ts-ignore types not implemented for plans JSON
21- const properties = plan .properties ;
26+ const features: any [] = Object .values (plan .properties );
2227
23- const markdown = ( content : any ) => {
24- if ( typeof content !== " string " ) return content ;
25-
26- return marked . parse ( content );
27- } ;
28+ const hasFree = features . some (( x ) => x . free );
29+ const hasPro = features . some (( x ) => x . pro ) ;
30+ const hasBiz = features . some (( x ) => x . biz );
31+ const hasEnt = features . some (( x ) => x . ent );
32+ const hasEntPlus = features . some (( x ) => x . ent_plus ) ;
2833---
2934
3035<table >
3136 <thead >
3237 <tr >
3338 <th ></th >
34- <th >Free</th >
35- <th >Pro</th >
36- <th >Business</th >
37- <th >Enterprise</th >
38- { plan . ent_plus && <th >{ plan .ent_plus } </th >}
39+ { hasFree && <th >Free</th >}
40+ { hasPro && <th >Pro</th >}
41+ { hasBiz && <th >Business</th >}
42+ { hasEnt && <th >Enterprise</th >}
43+ { hasEntPlus && <th >{ plan .ent_plus } </th >}
3944 </tr >
4045 </thead >
4146 <tbody >
4247 {
43- Object . entries ( properties ). map (([ _ , v ] : [ string , any ] ) => {
48+ features . map ((feature ) => {
4449 const renderTitle = (title : string ) => {
4550 const placeholder = " [[GLOSSARY_TOOLTIP_SNIPPETS_SUBREQUEST]]" ;
4651
@@ -67,12 +72,12 @@ const markdown = (content: any) => {
6772
6873 return (
6974 <tr >
70- <th set :html = { renderTitle (v .title )} />
71- <td set :html = { markdown (v .free )} />
72- <td set :html = { markdown (v .pro )} />
73- <td set :html = { markdown (v .biz )} />
74- <td set :html = { markdown (v .ent )} />
75- { plan . ent_plus && <td set :html = { markdown (v .ent_plus )} />}
75+ <th set :html = { renderTitle (feature .title )} />
76+ { hasFree && <td set :html = { markdown (feature .free )} />}
77+ { hasPro && <td set :html = { markdown (feature .pro )} />}
78+ { hasBiz && <td set :html = { markdown (feature .biz )} />}
79+ { hasEnt && <td set :html = { markdown (feature .ent )} />}
80+ { hasEntPlus && <td set :html = { markdown (feature .ent_plus )} />}
7681 </tr >
7782 );
7883 })
0 commit comments