@@ -49,6 +49,57 @@ const jsonSchemaCode = jsonSchema ? extractCode(jsonSchema) : null;
4949const typeSpecCode = typeSpec ? extractCode (typeSpec ) : null ;
5050const pythonCode = python ? extractCode (python ) : null ;
5151
52+ const jsonSchemaUrl = jsonSchema ? extractSchemaUrl (jsonSchema ) : null ;
53+ const typeSpecUrl = typeSpec ? extractGithubUrl (typeSpec ) : null ;
54+ const pythonUrl = python ? extractGithubUrl (python ) : null ;
55+
56+ /**
57+ * Constructs a schema URL from file path.
58+ * @param props - The code block configuration
59+ * @returns The schema URL for the file, or null if no file is specified
60+ */
61+ function extractSchemaUrl(props : CodeBlockConfig ): string | null {
62+ if (! props .file ) {
63+ return null ;
64+ }
65+
66+ const baseUrl = " https://commongrants.org/" ;
67+ const pathPrefix = " website/public/" ;
68+ let filePath = props .file .path ;
69+
70+ // Trim public directory prefix if present
71+ if (filePath .startsWith (pathPrefix )) {
72+ filePath = filePath .substring (pathPrefix .length );
73+ }
74+
75+ return ` ${baseUrl }${filePath } ` ;
76+ }
77+
78+ /**
79+ * Extracts a GitHub URL from file configuration.
80+ * @param props - The code block configuration
81+ * @returns The GitHub URL for the file, or null if no file is specified
82+ */
83+ function extractGithubUrl(props : CodeBlockConfig ): string | null {
84+ if (! props .file ) {
85+ return null ;
86+ }
87+
88+ const baseUrl = " https://github.com/HHS/simpler-grants-protocol/tree/main/" ;
89+ let url = ` ${baseUrl }/${props .file .path } ` ;
90+
91+ if (props .file .startLine || props .file .endLine ) {
92+ const start = props .file .startLine || 1 ;
93+ const end = props .file .endLine || start ;
94+ url += ` #L${start } ` ;
95+ if (end > start ) {
96+ url += ` -L${end } ` ;
97+ }
98+ }
99+
100+ return url ;
101+ }
102+
52103/**
53104 * Extracts code from either a literal string or a file.
54105 * @param props - The code block configuration
@@ -94,23 +145,23 @@ function extractCode(props: CodeBlockConfig): string {
94145 {
95146 jsonSchemaCode && (
96147 <TabItem label = " JSON Schema" >
97- <p >The JSON Schema for this model.</p >
148+ <p >The { jsonSchemaUrl && < a href = { jsonSchemaUrl } target = " _blank " rel = " noopener noreferrer " > JSON Schema</ a > } for this model.</p >
98149 <Code code = { jsonSchemaCode } lang = " yaml" />
99150 </TabItem >
100151 )
101152 }
102153 {
103154 typeSpecCode && (
104155 <TabItem label = " TypeSpec" >
105- <p >The TypeSpec code for this model.</p >
156+ <p >The { typeSpecUrl ? < a href = { typeSpecUrl } target = " _blank " rel = " noopener noreferrer " > TypeSpec code</ a > : " TypeSpec code " } for this model.</p >
106157 <Code code = { typeSpecCode } lang = " typespec" />
107158 </TabItem >
108159 )
109160 }
110161 {
111162 pythonCode && (
112163 <TabItem label = " Python" >
113- <p >The Python code for this model.</p >
164+ <p >The { pythonUrl ? < a href = { pythonUrl } target = " _blank " rel = " noopener noreferrer " > Python code</ a > : " Python code " } for this model.</p >
114165 <Code code = { pythonCode } lang = " python" />
115166 </TabItem >
116167 )
0 commit comments