From a771fe4fc9914ee4677eb8aa8945fd10bc5f1432 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 8 Aug 2021 22:42:37 +0100 Subject: [PATCH 1/5] :incoming_envelope: Extracts icon CDN endpoints into Defaults --- src/utils/defaults.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 09f5a2f6..1d731b9e 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -126,6 +126,15 @@ module.exports = { allesedv: 'https://f1.allesedv.com/128/$URL', webmasterapi: 'https://api.webmasterapi.com/v1/favicon/yEwx0ZFs0CSPshHq/$URL', }, + /* The URL to CDNs used for external icons. These are only loaded when required */ + iconCdns: { + fa: 'https://kit.fontawesome.com', + mdi: 'https://cdn.jsdelivr.net/npm/@mdi/font@5.9.55/css/materialdesignicons.min.css', + si: 'https://unpkg.com/simple-icons@v5/icons', + generative: 'https://ipsicon.io', + localPath: '/item-icons', + faviconName: 'favicon.ico', + }, /* Available built-in colors for the theme builder */ swatches: [ ['#eb5cad', '#985ceb', '#5346f3', '#5c90eb'], From 513be9d662e68ec0d322084234cbfb813192cd33 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 8 Aug 2021 22:43:37 +0100 Subject: [PATCH 2/5] :zap: Adds efficiency checks to determine which icon CDNs are needed --- src/views/Home.vue | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/views/Home.vue b/src/views/Home.vue index d8d56764..42adf811 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -43,7 +43,7 @@ import SettingsContainer from '@/components/Settings/SettingsContainer.vue'; import ItemGroup from '@/components/LinkItems/ItemGroup.vue'; -import Defaults, { localStorageKeys } from '@/utils/defaults'; +import Defaults, { localStorageKeys, iconCdns } from '@/utils/defaults'; export default { name: 'home', @@ -160,16 +160,21 @@ export default { availibleThemes.Default = '#'; return availibleThemes; }, - /* Checks if any of the icons are Font Awesome glyphs */ - checkIfFontAwesomeNeeded() { + /* Checks if any sections or items use icons from a given CDN */ + checkIfIconLibraryNeeded(prefix) { let isNeeded = false; if (!this.sections) return false; this.sections.forEach((section) => { - if (section.icon && section.icon.includes('fa-')) isNeeded = true; + if (section.icon && section.icon.includes(prefix)) isNeeded = true; section.items.forEach((item) => { - if (item.icon && item.icon.includes('fa-')) isNeeded = true; + if (item.icon && item.icon.includes(prefix)) isNeeded = true; }); }); + return isNeeded; + }, + /* Checks if any of the icons are Font Awesome glyphs */ + checkIfFontAwesomeNeeded() { + let isNeeded = this.checkIfIconLibraryNeeded('fa-'); const currentTheme = localStorage[localStorageKeys.THEME]; // Some themes require FA if (['material', 'material-dark'].includes(currentTheme)) isNeeded = true; return isNeeded; @@ -179,10 +184,23 @@ export default { if (this.appConfig.enableFontAwesome || this.checkIfFontAwesomeNeeded()) { const fontAwesomeScript = document.createElement('script'); const faKey = this.appConfig.fontAwesomeKey || Defaults.fontAwesomeKey; - fontAwesomeScript.setAttribute('src', `https://kit.fontawesome.com/${faKey}.js`); + fontAwesomeScript.setAttribute('src', `${iconCdns.fa}/${faKey}.js`); document.head.appendChild(fontAwesomeScript); } }, + /* Checks if any of the icons are Material Design Icons */ + checkIfMdiNeeded() { + return this.checkIfIconLibraryNeeded('mdi-'); + }, + /* Injects Material Design Icons, only if needed */ + initiateMaterialDesignIcons() { + if (this.checkIfMdiNeeded()) { + const mdiStylesheet = document.createElement('link'); + mdiStylesheet.setAttribute('rel', 'stylesheet'); + mdiStylesheet.setAttribute('href', iconCdns.mdi); + document.head.appendChild(mdiStylesheet); + } + }, /* Returns true if there is more than 1 sub-result visible during searching */ checkIfResults() { if (!this.sections) return false; @@ -204,6 +222,7 @@ export default { }, mounted() { this.initiateFontAwesome(); + this.initiateMaterialDesignIcons(); this.layout = this.layoutOrientation; this.itemSizeBound = this.iconSize; }, From 787b7a42c35320e5d3dd0294caba75bdba59cb4a Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 8 Aug 2021 22:44:27 +0100 Subject: [PATCH 3/5] :sparkles: Re: #139 Adds support for Material-Decison-Icons --- src/components/LinkItems/ItemIcon.vue | 53 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/components/LinkItems/ItemIcon.vue b/src/components/LinkItems/ItemIcon.vue index d4c5d39e..f2ee84ab 100644 --- a/src/components/LinkItems/ItemIcon.vue +++ b/src/components/LinkItems/ItemIcon.vue @@ -1,10 +1,19 @@ @@ -12,7 +21,7 @@