File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ const handleMathJax = ( rerun = false ) => {
2+ if ( typeof window === 'undefined' ) {
3+ return ;
4+ }
5+
6+ const mathjaxScript = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js' ;
7+ if ( ! window . MathJax ) {
8+ window . MathJax = {
9+ tex : {
10+ inlineMath : [ [ '\\(' , '\\)' ] ] ,
11+ } ,
12+ } ;
13+ }
14+
15+ let mathjaxScriptTag = document . querySelector ( `script[src="${ mathjaxScript } "]` ) ;
16+ if ( ! mathjaxScriptTag ) {
17+ let script = document . createElement ( 'script' ) ;
18+ script . type = 'text/javascript' ;
19+ script . src = mathjaxScript ;
20+ script . onload = function ( ) {
21+ window . MathJax && 'mathml2chtml' in window . MathJax && window . MathJax . mathml2chtml ( ) ;
22+ } ;
23+ document . head . appendChild ( script ) ;
24+ } else if ( rerun ) {
25+ window . MathJax && 'mathml2chtml' in window . MathJax && window . MathJax . mathml2chtml ( ) ;
26+ }
27+ } ;
28+
29+ export default handleMathJax ;
Original file line number Diff line number Diff line change 1+ export const triggerCustomWidgetEmbed = async ( pubId ) => {
2+ const frames = document . querySelectorAll ( '.hn-embed-widget' ) ;
3+ if ( frames . length === 0 ) {
4+ return ;
5+ }
6+ frames . forEach ( async ( frame ) => {
7+ try {
8+ const baseUrl = process . env . NEXT_PUBLIC_BASE_URL || '' ;
9+ const iframe = document . createElement ( 'iframe' ) ;
10+ const host = window . location . hostname ;
11+ iframe . id = `frame-${ frame . id } ` ;
12+ iframe . sandbox =
13+ 'allow-same-origin allow-forms allow-presentation allow-scripts allow-popups' ;
14+ iframe . src =
15+ host . indexOf ( '.hashnode.net' ) !== - 1 || host . indexOf ( '.app.localhost' ) !== - 1
16+ ? `${ baseUrl } /api/pub/${ pubId } /embed/${ frame . id } `
17+ : `https://embeds.hashnode.co?p=${ pubId } &w=${ frame . id } ` ;
18+ iframe . width = '100%' ;
19+ frame . innerHTML = '' ;
20+ frame . appendChild ( iframe ) ;
21+ setTimeout ( ( ) => {
22+ // TODO:
23+ // eslint-disable-next-line no-undef
24+ iFrameResize ( { log : false , autoResize : true } , `#${ iframe . id } ` ) ;
25+ } , 1000 ) ;
26+ frame . setAttribute ( 'class' , 'hn-embed-widget-expanded' ) ;
27+ } catch ( e ) {
28+ console . log ( e ) ;
29+ }
30+ } ) ;
31+ } ;
You can’t perform that action at this time.
0 commit comments