utterances
repository·master·Indexed 27 days ago
https://github.com/utterance/utterancesA lightweight, open-source comments widget that uses GitHub issues as a backend for storing and managing comments on websites, blogs, or wikis. Built with vanilla TypeScript and GitHub's Primer CSS, it provides a privacy-focused alternative to traditional comment systems by storing all data in the user's GitHub repository.
What's inside utterances
- Utterances is a lightweight comments widget that uses GitHub issues to store comment data. It is designed to be privacy-focused (no tracking or ads), free, and avoids vendor lock-in because all data resides in your GitHub repository. It uses GitHub's Primer CSS toolkit for styling and supports a dark theme. The widget is built with vanilla TypeScript and is optimized for performance by avoiding heavy JavaScript frameworks or font downloads.
How Utterances works
masterUtterances identifies the correct GitHub issue for a page by searching the GitHub issue search API using the page's
url,pathname, ortitle.- Issue Creation: If no matching issue is found, the
utterances-botwill automatically create a new issue the first time a user attempts to comment. - Commenting: Users can comment by authorizing the utterances app via the GitHub OAuth flow, which allows the app to post on their behalf. Alternatively, users can navigate to GitHub and comment directly on the associated issue.
- Issue Creation: If no matching issue is found, the
Embed the utterances widget via script tag
masterTo use the utterances widget, embed the client script into your HTML. The script automatically gathers configuration from its own
data-*attributes and from page metadata (like<link rel='canonical'>and<meta name='description'>).Supported configuration attributes (passed via
data-*):theme: The visual theme for the widget. You can also usedata-theme.- Other attributes are automatically extracted from the script tag and passed to the iframe.
Note: The widget will automatically attempt to use the user's preferred theme if
data-themeis not explicitly set.Load a JSON file from the repository
masterUseloadJsonFile<T>(path, html)to fetch and parse a file from the repository. Ifhtmlis set totrue, it returns the raw text instead of parsing JSON. The file is fetched from themasterbranch by default. If the file is a JSON file, it automatically handles Base64 decoding.Generate a GitHub OAuth login URL with getLoginUrl()
masterUsegetLoginUrl(redirect_uri: string)to generate the authorization URL required to start the GitHub OAuth flow. You must provide theredirect_uriwhere the user should be sent after authorization.Create a new issue
masterUsecreateIssueto create a new issue in the current repository context. This is typically used to initialize a discussion container for a specific topic. The function constructs a body containing the title, description, and a link to the document URL.Search for an issue by a specific term
masterUseloadIssueByTerm(term)to find an issue where thetermappears in the title. The function performs a GitHub search for issues in the current repository context. It returns the first issue that matches the term (case-insensitive) ornullif no issues are found.Load a page of issue comments
masterUseloadCommentsPage(issueNumber, page)to fetch a specific page of comments for a given issue. The number of comments per page is determined by thePAGE_SIZEconstant (defaulting to 25).Post a comment to an issue
masterUsepostComment(issueNumber, markdown)to add a new comment to an existing issue using Markdown formatting.Generate the reactions selection menu with `getReactionsMenuHtml`
masterUse
getReactionsMenuHtmlto generate the HTML for a popover menu that allows users to select a reaction.Parameters:
url: The endpoint URL for the reaction action.align: The alignment of the menu, either'center'or'right'.
If
alignis set to'center', the menu is positioned usingleft: 50%; transform: translateX(-50%)and the summary element is giventabindex="-1".Render Markdown using GitHub's API
masterUserenderMarkdown(text)to convert Markdown text into HTML using GitHub's official Markdown API (GFM mode). This ensures the rendered HTML matches what users see on GitHub.Generate the sign-in prompt menu with `getSignInToReactMenuHtml`
masterUse
getSignInToReactMenuHtmlto generate the HTML for a popover menu that prompts unauthenticated users to sign in to add a reaction.Parameters:
align: The alignment of the menu, either'center'or'right'.