CWGI - Set up the client side

Client side code is built with Solid.js and TailwindCSS, so the size of the bundle is relatively small (~ 23Kb). The code is available on GitHub.

How to use

<!-- index.html -->
<link rel="stylesheet" href="https://cwgi-cli.jw1.dev/style.css">
<div id="cwgi_box"></div>
<script src="https://cwgi-cli.jw1.dev/cwgi.iife.js"></script>
// index.js
_CWGI.init()
ES module version
<!-- index.html -->
<link rel="stylesheet" href="https://cwgi-cli.jw1.dev/style.css">
<div id="cwgi_box"></div>
// index.js

// you can use it just like this or download it to your project and import it
import {init} from 'https://cwgi-cli.jw1.dev/cwgi.js'

init()

Options

interface CWGI_Options {
  owner: string,
  repo: string,
  clientId: string,
  darkMode?: boolean,
  proxy?: string,
  reactions?: boolean,
  remoteMarkdownRendering?: boolean,
  markdownRenderingEndpoint?: string
}

declare function init(githubIssueId: number, options: CWGI_Options)

Use in SPAs

Just call the init function again when the route changes, the function will automatically remove the previous instance and create a new one.

// router.js
import {init} from 'cwgi'
import {useRoute} from 'vue-router'

const route = useRoute()

route.afterEach(() => {
  init()
})

Programmatic dark mode

Just like in SPAs, you can call the init function with the darkMode option.

// index.js
import {init} from 'cwgi'

init(1, {darkMode: true})

Build the bundle yourself

  1. Fork the repo: jw-12138/cwgi-cli
  2. Go to Cloudflare Dashboard -> Workers & Pages -> Create, Switch to Pages tab, and click Connect to Git.
  3. Choose the repository you just forked (should be named as cwgi-cli), and click Begin Setup.
  4. Choose Vue as the framework preset (though the code is written in Solid.js), and click Save and Deploy.

When the deployment is done, you should be able to get a URL like https://cwgi-cli.workers.dev, and you can replace the URL in the pre-built bundle with this one.

Also, remember to set a custom domain for this worker in order to use it in the Mainland China.


That’s it, you’ve covered pretty much everything, the comment system should be able to run without a problem!