File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
plugins/adr/src/components/AdrReader Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @backstage-community/plugin-adr ' : patch
3+ ---
4+
5+ FrontMatter decorator shows now a local date without time and timezone instead of a full ` Date.toString() ` string. It also uppercase the first character for lowercase-only strings.
Original file line number Diff line number Diff line change @@ -54,14 +54,27 @@ export const adrDecoratorFactories = Object.freeze({
5454 let table = '' ;
5555 const attrs = parsedFrontmatter . attributes ;
5656 if ( Object . keys ( attrs ) . length > 0 ) {
57- const stripNewLines = ( val : unknown ) =>
58- String ( val ) . replaceAll ( '\n' , '<br/>' ) ;
57+ // Convert "alllowercase" strings into "First char uppercase" variants
58+ const uppercaseFirstChar = ( val : string ) => {
59+ if ( val . match ( / ^ [ a - z ] + $ / ) ) {
60+ return val . substring ( 0 , 1 ) . toUpperCase ( ) + val . substring ( 1 ) ;
61+ }
62+ return val ;
63+ } ;
64+ const stripNewLines = ( val : unknown ) => {
65+ if ( val instanceof Date ) {
66+ return val . toLocaleString ( undefined , { dateStyle : 'medium' } ) ;
67+ }
68+ return String ( val ) . replaceAll ( '\n' , '<br/>' ) ;
69+ } ;
5970 const row = ( vals : string [ ] ) => `|${ vals . join ( '|' ) } |\n` ;
60- table = `${ row ( Object . keys ( attrs ) ) } ` ;
61- table += `${ row ( Object . keys ( attrs ) . map ( ( ) => '---' ) ) } ` ;
62- table += `${ row ( Object . values ( attrs ) . map ( stripNewLines ) ) } \n\n` ;
71+ table = row ( Object . keys ( attrs ) . map ( uppercaseFirstChar ) ) ;
72+ table += row ( Object . keys ( attrs ) . map ( ( ) => '---' ) ) ;
73+ table += row ( Object . values ( attrs ) . map ( stripNewLines ) ) ;
74+ table += '\n' ;
75+ return { content : table + parsedFrontmatter . content } ;
6376 }
64- return { content : table + parsedFrontmatter . content } ;
77+ return { content } ;
6578 } ;
6679 } ,
6780} ) ;
You can’t perform that action at this time.
0 commit comments