(req: express.Request, link: ExpandedShortLink | null, config: any)
| 234 | } |
| 235 | |
| 236 | getMetaDataFromLink(req: express.Request, link: ExpandedShortLink | null, config: any) { |
| 237 | const metadata: ShortLinkMetaData = { |
| 238 | ogTitle: 'Compiler Explorer', |
| 239 | }; |
| 240 | |
| 241 | if (link) { |
| 242 | if (link.specialMetadata) { |
| 243 | metadata.ogDescription = link.specialMetadata.description.S; |
| 244 | metadata.ogAuthor = link.specialMetadata.author.S; |
| 245 | metadata.ogTitle = link.specialMetadata.title.S; |
| 246 | } |
| 247 | |
| 248 | if (link.created) metadata.ogCreated = link.created; |
| 249 | } |
| 250 | |
| 251 | if (!metadata.ogDescription) { |
| 252 | let lang: Language | undefined; |
| 253 | let source = ''; |
| 254 | |
| 255 | const sources = utils.glGetMainContents(config.content); |
| 256 | if (sources.editors.length === 1) { |
| 257 | const editor = sources.editors[0]; |
| 258 | lang = unwrap(this.apiHandler).languages[editor.language]; |
| 259 | source = editor.source; |
| 260 | } else { |
| 261 | const normalizer = new ClientStateNormalizer(); |
| 262 | normalizer.fromGoldenLayout(config); |
| 263 | const clientstate = normalizer.normalized; |
| 264 | |
| 265 | if (clientstate.trees && clientstate.trees.length === 1) { |
| 266 | const tree = clientstate.trees[0]; |
| 267 | lang = unwrap(this.apiHandler).languages[tree.compilerLanguageId]; |
| 268 | |
| 269 | if (tree.isCMakeProject) { |
| 270 | const firstSource = tree.files.find(file => { |
| 271 | return file.filename?.startsWith('CMakeLists.txt'); |
| 272 | }); |
| 273 | |
| 274 | if (firstSource) { |
| 275 | source = firstSource.content; |
| 276 | } |
| 277 | } else { |
| 278 | const firstSource = tree.files.find(file => { |
| 279 | return file.filename?.startsWith('example.'); |
| 280 | }); |
| 281 | |
| 282 | if (firstSource) { |
| 283 | source = firstSource.content; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (lang) { |
| 290 | metadata.ogDescription = this.filterCode(req, source, lang); |
| 291 | metadata.ogTitle += ` - ${lang.name}`; |
| 292 | if (sources && sources.compilers.length === 1) { |
| 293 | const compilerId = sources.compilers[0].compiler; |
no test coverage detected