Skip to content

Commit

Permalink
bundle the favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed May 4, 2023
1 parent 29ab161 commit 5e0d8d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions frontend/djangoBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ Handlebars.registerHelper('if_eq', function (a, b, opts) {
})

function generateHTML(
faviconFileName,
srcFileName,
spaceGroteskFontFileName,
interFontFileName
) {
const templateString = fs.readFileSync(handlebarsTemplatePath, 'utf-8')
const template = Handlebars.compile(templateString)
return template({
faviconUrl: `react/${faviconFileName}`,
reactUrl: `react/${srcFileName}`,
spaceGroteskFontUrl: `react/${spaceGroteskFontFileName}`,
interFontUrl: `react/${interFontFileName}`,
Expand All @@ -53,14 +55,11 @@ function generateHTML(
bundler.on('bundled', (bundle) => {
const indexHtml = fs.readFileSync(bundle.name, 'utf-8')

const srcFileName = getHashedFileName(indexHtml, 'src', 'js')
const spaceGroteskFileName = getHashedFileName(indexHtml, 'SpaceGrotesk-VariableFont_wght', 'ttf')
const interFileName = getHashedFileName(indexHtml, 'Inter-VariableFont_slnt,wght', 'ttf')

const HTML = generateHTML(
srcFileName,
spaceGroteskFileName,
interFileName
getHashedFileName(indexHtml, 'favicon', 'ico'),
getHashedFileName(indexHtml, 'src', 'js'),
getHashedFileName(indexHtml, 'SpaceGrotesk-VariableFont_wght', 'ttf'),
getHashedFileName(indexHtml, 'Inter-VariableFont_slnt,wght', 'ttf')
)

fs.writeFile(`${templateFolder}/portal.html`, HTML, (error) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/handlebars_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<title>Code for Life</title>
<link rel="shortcut icon" href="{% static 'favicon.ico' %}" type="image/x-icon" />
<link rel="icon" type="image/x-icon" href="{% static '{{ faviconUrl }}' %}">
<style>
html,
body,
Expand Down
1 change: 1 addition & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Code for Life</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
html,
body,
Expand Down

0 comments on commit 5e0d8d5

Please sign in to comment.