Skip to content

Commit

Permalink
Update the page title to generate better link previews
Browse files Browse the repository at this point in the history
  • Loading branch information
alexewerlof committed Apr 19, 2024
1 parent 92a354a commit b2a524b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AlertComponent from './components/alert.js'
import BurnRateComponent from './components/burn-rate.js'
import ErrorBudgetComponent from './components/error-budget.js'
import ExtLink from './components/ext-link.js'
import { setTitle } from './lib/header.js'
import { percent, percentToRatio, toFixed, clamp } from './lib/math.js'
import { daysToSeconds } from './lib/time.js'
import { Window } from './lib/window.js'
Expand Down Expand Up @@ -70,7 +71,10 @@ export const app = createApp({
if (newVal !== oldVal) {
this.estimatedValidEvents = Math.round(this.estimatedValidEvents * newVal / oldVal)
}
}
},
title(newTitle) {
setTitle(document, newTitle)
},
},
mounted() {
this.loadState(urlToState(window.location.href))
Expand Down
12 changes: 12 additions & 0 deletions lib/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function normalizeTitle(title) {
if (title) {
return `${title} | SLC`
}
return 'Service Level Calculator'
}

export function setTitle(document, title) {
title = normalizeTitle(title)
document.title = title
document.querySelector('meta[property="og:title"]').setAttribute('content', title)
}

0 comments on commit b2a524b

Please sign in to comment.