Add meta helper
This commit is contained in:
parent
cf565c3eaf
commit
9d579b1dd3
1 changed files with 17 additions and 0 deletions
17
meta.js
Normal file
17
meta.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export default new Proxy(document.head, {
|
||||||
|
get: (head, prop) => head.querySelector(`[name="${prop}"]`)?.content,
|
||||||
|
set: (head, prop, value) => {
|
||||||
|
let meta = head.querySelector(`[name="${prop}"]`)
|
||||||
|
if (!meta) {
|
||||||
|
meta = document.createElement("meta")
|
||||||
|
meta.name = prop
|
||||||
|
head.append(meta)
|
||||||
|
}
|
||||||
|
meta.content = value
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
deleteProperty: (head, prop) => {
|
||||||
|
head.querySelector(`[name=${prop}]`)?.remove()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
})
|
Loading…
Reference in a new issue