File tree Expand file tree Collapse file tree
src/components/CallToAction/Download Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,8 +57,31 @@ const descriptionId = `${id}-description`
5757// Construct the download landing page URL
5858const downloadUrl = ` /downloads/${normalizedResource } `
5959const downloadEntries = await getCollection (' downloads' )
60+
61+ const matchesDownloadResource = (
62+ download : (typeof downloadEntries )[number ],
63+ expectedResource : string
64+ ) => {
65+ const normalizedDownloadId = download .id .replace (/ \\ / g , ' /' )
66+
67+ if (normalizedDownloadId === expectedResource ) {
68+ return true
69+ }
70+
71+ if (normalizedDownloadId .replace (/ \/ download$ / , ' ' ) === expectedResource ) {
72+ return true
73+ }
74+
75+ if (normalizedDownloadId .split (' /' )[0 ] === expectedResource ) {
76+ return true
77+ }
78+
79+ const normalizedFilePath = download .filePath ?.replace (/ \\ / g , ' /' )
80+ return normalizedFilePath ?.includes (` /${expectedResource }/download. ` ) ?? false
81+ }
82+
6083const matchedDownloadEntry = downloadEntries .find (
61- download => download . id . replace ( / \/ download$ / , ' ' ) === normalizedResource
84+ download => matchesDownloadResource ( download , normalizedResource )
6285)
6386const directDownloadFileName = matchedDownloadEntry ?.data .fileName ?.trim ()
6487const directDownloadUrl = directDownloadFileName
You can’t perform that action at this time.
0 commit comments