Skip to content

Commit

Permalink
Add support for custom SiteURL
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnaderi committed Sep 29, 2023
1 parent 125a404 commit b34eb1e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "ir.quera.mattermost-vazirmatn",
"name": "Mattermost Vazirmatn",
"description": "Changes Mattermost font to Vazirmatn.",
"version": "1.0.1",
"version": "1.0.2",
"min_server_version": "5.12.0",
"webapp": {
"bundle_path": "webapp/dist/main.js"
Expand Down
4 changes: 2 additions & 2 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mattermost-vazirmatn",
"version": "1.0.1",
"version": "1.0.2",
"description": "Changes Mattermost font to Vazirmatn.",
"main": "src/index.js",
"scripts": {
Expand Down
23 changes: 23 additions & 0 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import manifest from './manifest';
import './style.css';

class MattermostVazirmatnPlugin {
// eslint-disable-next-line class-methods-use-this
initialize(registry, store) {
const state = store.getState();
const siteURL = state?.entities?.general?.config?.SiteURL || state?.entities?.admin?.config?.ServiceSettings?.SiteURL || '';

console.log('initializing mattermost-vazirmatn plugin. SiteURL:', siteURL);

// Load VazirmatnNL font face
const fontURL = `${siteURL}/plugins/${manifest.id}/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2`;
const fontSrc = `url(${fontURL}) format('woff2 supports variations'), url(${fontURL}) format('woff2-variations')`;
const fontFace = new FontFace('VazirmatnNL', fontSrc, {
weight: '100 900',
style: 'normal',
display: 'swap',
// Only apply to arabic script.
// https://en.wikipedia.org/wiki/Arabic_script_in_Unicode
unicodeRange: 'U+0600-06FF, U+0750-077F, U+08A0-08FF, U+0870-089F, U+FB50-FDFF, U+FE70-FEFF, U+1EE00-1EEFF',
});
fontFace.load().then((loadedFace) => {
document.fonts.add(loadedFace);
console.log('VazirmatnNL font loaded.');
});
}
}

window.registerPlugin(manifest.id, new MattermostVazirmatnPlugin());
14 changes: 0 additions & 14 deletions webapp/src/style.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
@font-face {
font-family: VazirmatnNL;
src: url("/plugins/ir.quera.mattermost-vazirmatn/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2") format('woff2 supports variations'),
url("/plugins/ir.quera.mattermost-vazirmatn/public/fonts/vazirmatn-v33.003/Vazirmatn-NL[wght].woff2") format('woff2-variations');
font-weight: 100 900;
font-style: normal;
font-display: swap;
/**
* Only apply to arabic script.
* https://en.wikipedia.org/wiki/Arabic_script_in_Unicode
*/
unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+0870-089F, U+FB50-FDFF, U+FE70-FEFF, U+1EE00-1EEFF;
}

/* https://github.com/mattermost/mattermost/blob/master/webapp/channels/src/sass/base/_typography.scss */
body, .app__body.font--open_sans {
font-family: VazirmatnNL, 'Open Sans', sans-serif !important;
Expand Down

0 comments on commit b34eb1e

Please sign in to comment.