giscus comments
authorMichael Wallner <mike@php.net>
Fri, 11 Feb 2022 20:19:06 +0000 (21:19 +0100)
committerMichael Wallner <mike@php.net>
Fri, 11 Feb 2022 20:50:00 +0000 (21:50 +0100)
views/comments.giscus.phtml [new file with mode: 0644]
views/index.phtml
views/layout.phtml
views/mdref.phtml
views/stub.phtml

diff --git a/views/comments.giscus.phtml b/views/comments.giscus.phtml
new file mode 100644 (file)
index 0000000..c2e621f
--- /dev/null
@@ -0,0 +1,15 @@
+<?php if (isset($providerData->data)) : ?>
+       <style>.giscus-frame {min-height: 16em;}</style>
+       <script>
+               function giscus_load(button) {
+                       let script = document.createElement("script");
+                       <?php foreach ($providerData->data as $key => $val) : ?>
+                       script.setAttribute("data-<?=$key?>", <?php var_export($val)?>);
+                       <?php endforeach; ?>
+
+                       script.src = "//giscus.app/client.js";
+                       button.parentNode.replaceChild(script, button);
+               }
+       </script>
+       <button class="activator" onclick="giscus_load(this)">Show Comments from Github Discussions</button>
+<?php endif; ?>
index d2bd1fe741cb2966216b3da3dec823d167150420..531a87b67bf3d84b3f609c0fc1c66a581a0185ad 100644 (file)
@@ -9,12 +9,12 @@
        <p style="white-space:pre-wrap"><?= $esc($text) ?></p>
 <?php elseif (isset($refs)) : ?>
        <?php foreach ($refs as $repo) : /* @var \mdref\Repo $repo */ ?>
-               <?php foreach ($repo as $entry) : /* @var \mdref\Entry $entry */ ?>
+               <?php foreach ($repo as $root) : /* @var \mdref\Entry $root */ ?>
 
-               <h2 id="<?= $anchor($entry->getTitle()) ?>">
-                       <a href="<?= $esc($entry->getName()) ?>"
-                       ><?= $esc($entry->getTitle()) ?></a></h2>
-               <div><?= $quick($entry->getIntro()) ?></div>
+               <h2 id="<?= $anchor($root->getTitle()) ?>">
+                       <a href="<?= $esc($root->getName()) ?>"
+                       ><?= $esc($root->getTitle()) ?></a></h2>
+               <div><?= $quick($root->getIntro()) ?></div>
                        <?php if ($repo->hasStub($stub)) : ?>
                                <?php include __DIR__ . "/stub.phtml"; ?>
                        <?php endif; ?>
index b0e96a8667a00e1210e100af0fd4760ddeb5766d..21693f6dfce8a327e9aa2a348d39be6c41e9ec37 100644 (file)
                <?php else: ?>
                        <?php include __DIR__."/index.phtml" ?>
                <?php endif; ?>
+               <?php if (isset($entry) && ($comments = $entry->getRepo()->getCommentProvider())) : ?>
 
+                       <div class="comments">
+                               <?php foreach ($comments as $providerName => $providerData) : ?>
+                                       <?php include __DIR__."/comments.$providerName.phtml" ?>
+                               <?php endforeach; ?>
+
+                       </div>
+               <?php endif; ?>
 
                        <footer>
                                <?php include __DIR__."/footer.phtml" ?>
@@ -37,7 +45,7 @@
                        </footer>
                <?php if (isset($baseUrl)) : ?>
 
-                       <script src="index.js"></script>
+                       <script src="index.js" defer></script>
                <?php endif; ?>
 
                </div>
index cce2d1fa7c2651ffbcd39cd1a06b7891c842976c..725782eebbabc917325e26ae8eea30ec232d3bf5 100644 (file)
@@ -2,7 +2,7 @@
 
 <?= $file($entry->getPath()) ?>
 
-<?php if ($entry->isRoot() && $entry->getRepo()->hasStub($stub)) : ?>
+<?php if ($entry->isRoot() && $entry->getRepo()->hasStub($stub)) : $root = $entry; ?>
        <h2 id="Editor.Stub:">Editor Stub:</h2>
        <p>This extension provides a stub file four your editor's auto-completion.</p>
        <?php include __DIR__ . "/stub.phtml"; ?>
index 140cd064d783e4f9602ac638626630109200a963..a29faf825ac5058bc4b05a538989c3484cc44a34 100644 (file)
@@ -3,9 +3,9 @@
                                        <ul style="list-style-type: '&raquo;'">
                                                <li>
                                                        <?php if (defined("REF2HTML") && constant("REF2HTML")) :?>
-                                                       <a href="<?= $entry->getName() ?>.stub.php"><?= $entry->getName() ?>.stub.php</a><br>
+                                                       <a href="<?= $root->getName() ?>.stub.php"><?= $root->getName() ?>.stub.php</a><br>
                                                        <?php else : ?>
-                                                       <a href="stub?ref=<?= $entry->getName() ?>"><?= $entry->getName() ?>.stub.php</a><br>
+                                                       <a href="stub?ref=<?= $root->getName() ?>"><?= $root->getName() ?>.stub.php</a><br>
                                                        <?php endif; ?>
                                                        <small>
                                                                Last modified: