forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: precompile template urls at build time + bs5 btn on agenda loadi…
…ng screen (ietf-tools#4679) * fix: precompile template urls at build time + bs5 btn on agenda loading screen * fix: add back url store changes
- Loading branch information
Showing
15 changed files
with
172 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* DO NOT add the urls here directly. Edit the urls.json file instead. | ||
* The urls are automatically precompiled into the variable below at build time. | ||
*/ | ||
const urls = { /* __COMPILED_URLS__ */ } | ||
|
||
/** | ||
* Get an URL and replace tokens with provided values. | ||
* | ||
* @param {string} key The key of the URL template to use. | ||
* @param {Object} [tokens] An object of tokens to replace in the URL template. | ||
* @returns {string} URL with tokens replaced with the provided values. | ||
*/ | ||
export const getUrl = (key, tokens = {}) => { | ||
if (!key) { throw new Error('Must provide a key for getUrl()') } | ||
if (!urls[key]) { throw new Error('Invalid getUrl() key') } | ||
return urls[key](tokens) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"bofDefinition": "https://www.ietf.org/how/bofs/", | ||
"meetingCalIcs": "/meeting/{meetingNumber}/agenda.ics", | ||
"meetingDetails": "/meeting/{meetingNumber}/session/{eventAcronym}/", | ||
"meetingMaterialsPdf": "/meeting/{meetingNumber}/agenda/{eventAcronym}-drafts.pdf", | ||
"meetingMaterialsTar": "/meeting/{meetingNumber}/agenda/{eventAcronym}-drafts.tgz", | ||
"meetingMeetechoRecordings": "https://www.meetecho.com/ietf{meetingNumber}/recordings#{eventAcronym}", | ||
"meetingNotes": "https://notes.ietf.org/notes-ietf-{meetingNumber}-{eventAcronym}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createFilter } from '@rollup/pluginutils' | ||
import template from 'lodash/template' | ||
import transform from 'lodash/transform' | ||
import fs from 'fs/promises' | ||
|
||
export default function precompileLodashTemplates(options = {}) { | ||
const filter = createFilter(options.include, options.exclude) | ||
return { | ||
name: 'precompile-lodash-templates', | ||
enforce: 'pre', | ||
async transform(code, id) { | ||
if (!filter(id)) { return } | ||
|
||
const jsonPath = `${id}on` | ||
const urls = JSON.parse(await fs.readFile(jsonPath, { encoding: 'utf8' })) | ||
|
||
const interpolate = /{([\s\S]+?)}/g | ||
const compiledUrls = transform(urls, (result, value, key) => { | ||
result.push(`"${key}": ${template(value.replaceAll('{', '{data.'), { interpolate, variable: 'data' }).source.replace('function(obj)', '(obj) =>')}`) | ||
}, []) | ||
|
||
console.info(code.replace('/* __COMPILED_URLS__ */', compiledUrls.join(',\n'))) | ||
|
||
return { | ||
code: code.replace('/* __COMPILED_URLS__ */', compiledUrls.join(',\n')), | ||
map: null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters