Last active
September 22, 2022 07:25
-
-
Save dbwodlf3/172d25840094f4b60b5268d57a44e7f7 to your computer and use it in GitHub Desktop.
parse opengraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Parsing only meta in headtag. */ | |
export function parse_opengraph(inputHTML) { | |
const filter_head = /<head>[^]*<\/head>/i; | |
let filter_meta_og = /<meta[^>]*property[^>]*=[^>]*(og:)[^>]*>/ig; | |
let head = inputHTML.match(filter_head)[0]; | |
const metas = head.match(filter_meta_og); | |
if(!metas) return; | |
const opengraph = {} | |
for(const meta of metas) { | |
opengraph[`${(meta.match(/og\s*:([a-zA-Z]*)/)[1])}`] = meta.match(/content[^=]*="(.*)"|'(.*)'/)[1]; | |
} | |
return opengraph; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment