Skip to content

Commit

Permalink
Add favicon to Playroom site (#309)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Jervis <bjervis@seek.com.au>
Co-authored-by: Remus Mate <3297808+mrm007@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 18, 2023
1 parent 4fb69cb commit e3b820b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-moons-check.md
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Add favicon to Playroom site.
Binary file added images/favicon-inverted.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/makeWebpackConfig.js
Expand Up @@ -141,6 +141,10 @@ module.exports = async (playroomConfig, options) => {
include: path.dirname(require.resolve('codemirror/package.json')),
use: [MiniCssExtractPlugin.loader, require.resolve('css-loader')],
},
{
test: /\.png$/i,
type: 'asset/resource',
},
],
},
optimization: {
Expand All @@ -163,6 +167,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html',
favicon: 'images/favicon.png',
base: playroomConfig.baseUrl,
}),
new HtmlWebpackPlugin({
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Expand Up @@ -2,6 +2,8 @@ import { renderElement } from './render';
import Playroom from './Playroom/Playroom';
import { StoreProvider } from './StoreContext/StoreContext';
import playroomConfig from './config';
import faviconPath from '../images/favicon.png';
import faviconInvertedPath from '../images/favicon-inverted.png';

const polyfillIntersectionObserver = () =>
typeof window.IntersectionObserver !== 'undefined'
Expand All @@ -14,6 +16,15 @@ polyfillIntersectionObserver().then(() => {
const outlet = document.createElement('div');
document.body.appendChild(outlet);

const selectedElement = document.head.querySelector('link[rel="icon"]');
const favicon = window.matchMedia('(prefers-color-scheme: dark)').matches
? faviconInvertedPath
: faviconPath;

if (selectedElement) {
selectedElement.setAttribute('href', favicon);
}

const renderPlayroom = ({
themes = require('./themes'),
components = require('./components'),
Expand Down

0 comments on commit e3b820b

Please sign in to comment.