Skip to content

Commit 21ad712

Browse files
committed
add fallback to default.png if image path can't be resolved
1 parent 831a467 commit 21ad712

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
11.7 KB
Loading

src/components/CardModel.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ export default {
104104
}
105105
},
106106
methods: {
107+
/**
108+
* Resolves fetching an image file from the file system.
109+
*
110+
* @param {String} path - the path to the image
111+
* @return {Object} - the image object from the require call
112+
*/
107113
resolveImage(path) {
108-
return require('../assets/images/cards/' + path);
114+
try{
115+
return require(`../assets/images/cards/${path}`);
116+
} catch(err) {
117+
console.log(err);
118+
return require(`../assets/images/cards/default.png`);
119+
}
109120
},
110121
/**
111122
* Adjusts the size of the font to be displayed on a CardModel
@@ -125,6 +136,8 @@ export default {
125136
baselineEm = isAllCaps ? 0.7 : 0.8;
126137
} else if (length >= 18) {
127138
baselineEm = isAllCaps ? 0.9 : 1.0;
139+
} else if (length >= 15 && isAllCaps) {
140+
baselineEm = 0.9;
128141
}
129142
return baselineEm;
130143
}

0 commit comments

Comments
 (0)