57 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <script>
 | |
|   var disqus_config = function () {
 | |
|     this.page.url = '{{ .Permalink }}';
 | |
|     this.page.identifier = '{{ .RelPermalink }}';
 | |
|   };
 | |
| 
 | |
|   function addDisqus() {
 | |
|     let disqusThread = document.createElement('div');
 | |
|     let paragraph = document.createElement('p');
 | |
| 
 | |
|     disqusThread.id = 'disqus_thread';
 | |
|     paragraph.className = 'text-center text-muted small';
 | |
|     paragraph.innerHTML = 'Comments powered by <a href="https://disqus.com/">Disqus</a>.';
 | |
|     disqusThread.appendChild(paragraph);
 | |
| 
 | |
|     const footer = document.querySelector('footer');
 | |
|     footer.insertAdjacentElement("beforebegin", disqusThread);
 | |
|   }
 | |
| 
 | |
|   {{/* Auto switch theme */}}
 | |
|   function reloadDisqus(event) {
 | |
|     if (event.source === window && event.data && event.data.id === Theme.ID) {
 | |
|       {{/* Disqus hasn't been loaded */}}
 | |
|       if (typeof DISQUS === 'undefined') {
 | |
|         return;
 | |
|       }
 | |
| 
 | |
|       if (document.readyState == 'complete') {
 | |
|         DISQUS.reset({ reload: true, config: disqus_config });
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   addDisqus();
 | |
| 
 | |
|   if (Theme.switchable) {
 | |
|     addEventListener('message', reloadDisqus);
 | |
|   }
 | |
| 
 | |
|   {{/* Lazy loading */}}
 | |
|   var disqusObserver = new IntersectionObserver(
 | |
|     function (entries) {
 | |
|       if (entries[0].isIntersecting) {
 | |
|         var d = document,
 | |
|           s = d.createElement('script');
 | |
|         s.src = 'https://{{ .Site.Params.comments.disqus.shortname }}.disqus.com/embed.js';
 | |
|         s.setAttribute('data-timestamp', +new Date());
 | |
|         (d.head || d.body).appendChild(s);
 | |
| 
 | |
|         disqusObserver.disconnect();
 | |
|       }
 | |
|     },
 | |
|     { threshold: [0] }
 | |
|   );
 | |
| 
 | |
|   disqusObserver.observe(document.getElementById('disqus_thread'));
 | |
| </script> | 
