-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathpage.js
More file actions
38 lines (33 loc) · 1.35 KB
/
page.js
File metadata and controls
38 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import client from './client'
import state from './state'
import windowEvent from './windowEvent'
const page = {
...state.page,
event: 'nullstack.page',
}
delete state.page
const pageProxyHandler = {
set(target, name, value, receiver) {
const result = Reflect.set(target, name, value, receiver)
if (name === 'title') {
document.title = value
document.querySelector('head > meta[property="og:title"]').setAttribute('content', value)
windowEvent('page')
} else if (name === 'description') {
document.querySelector('head > meta[name="description"]').setAttribute('content', value)
document.querySelector('head > meta[property="og:description"]').setAttribute('content', value)
} else if (name === 'locale') {
document.querySelector('html').setAttribute('lang', value)
document.querySelector('head > meta[property="og:locale"]').setAttribute('content', value)
} else if (name === 'image') {
document.querySelector('head > meta[property="og:image"]').setAttribute('content', value)
} else if (name === 'canonical') {
canonical = (path.indexOf('//') === -1) ? router.base + value : value
document.querySelector('head > link[rel="canonical"]').setAttribute('href', canonical)
}
client.update()
return result
},
}
const proxy = new Proxy(page, pageProxyHandler)
export default proxy