utterance / utterances

:crystal_ball: A lightweight comments widget built on GitHub issues
https://utteranc.es
MIT License
8.68k stars 566 forks source link

Should all issues be within the same repository? #217

Closed neruthes closed 4 years ago

neruthes commented 4 years ago

Recently I have been working on www.cyberparliament.org, where people post mainly URLs of issues. I would like to have a comment area where readers can directly comment under the given issue without actually jumping to the issue page, but the homepage of Utterances suggests that it is not possible... 🤔

Verassitnh commented 4 years ago

@neruthes, In what ways does the homepage suggest that your idea cannot be done?

Server:

app.get('/repo/:repo/issue/:issue', (req, res) => {
    let commentCode = 
         '<script src="https://utteranc.es/client.js"
                 repo="' + req.params.repo + '"
                 issue-number="' + req.params.issue + '"
                 theme="github-light"
                 crossorigin="anonymous"
                 async>
         </script>'

    res.send(
         fs.readFileSync('issue.html')
         .split('<!--%COMMENTS%-->')
         .join(commentCode)
    )

});

Client:

<script src="https://utteranc.es/client.js"
        id="comments"
        theme="github-light"
        crossorigin="anonymous"
        async>
</script>

<script>
  const repo = // Your code to get the repo
  const issue = // Your code to get the issue number
  const script = document.getElementById('comments')

  script.setAttribute('repo', repo)
  script.setAttribute('issue-number', issue)
</script>

If you dynamically adjust the script tags attributes, you can do it.

neruthes commented 4 years ago

@Gninoskcaj Thank you. I just figured it out. :)

However, now I am confused by a strange behavior — the script is not automatically executed upon rendering; I have to change its tagName to another value then change it back, in order to make the browser execute it.

Also, GitHub login does not work. I always get back to please-login status after a GitHub login operation.

It will be nice if you have any idea on this.

Example: https://www.cyberparliament.org/?rpr-13

Verassitnh commented 4 years ago

@neruthes, Is it similar to this? https://github.com/utterance/utterances/issues/1#issuecomment-458319416

btw, It seems to work fine here: https://jsbin.com/tuzuriwiwe/edit?html,output

jdanyow commented 4 years ago

Issues can be posted to any repo with utterances installed.

neruthes commented 4 years ago

@Gninoskcaj Yes, really similar. I am struggling with it pretty much.

neruthes commented 4 years ago

Latest update: I noticed that execution failure is a general problem whenever I use .innerHTML = to add <script> tags. Then I tried...

parentNode.appendChild(document.createElement('script').setAttribute(...))

... and the script successfully executed.

Hope this may be helpful for those who might encounter the same problem in future.