Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add casibase widget JS via CDN #260

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ var _hmt = _hmt || [];
src: "/js/clarity.js",
async: true,
},
{
src: "/js/casibase-tracker.js",
hsluoyz marked this conversation as resolved.
Show resolved Hide resolved
async: true,
},
],
presets: [
[
Expand Down
84 changes: 0 additions & 84 deletions src/ChatWidget/ChatButton.jsx

This file was deleted.

64 changes: 0 additions & 64 deletions src/ChatWidget/chatStyles.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/ChatWidget/chatWidget.js

This file was deleted.

8 changes: 1 addition & 7 deletions src/components/HomepageFeatures/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {useEffect} from "react";
import React from "react";
import clsx from "clsx";
import styles from "./styles.module.css";
import Translate from "@docusaurus/Translate";
import {useColorMode} from "@docusaurus/theme-common";
import {initChatWidget} from "../../ChatWidget/chatWidget";

const FeatureList = [
{
Expand Down Expand Up @@ -70,11 +69,6 @@ function Feature({title, path, description}) {
}

export default function HomepageFeatures() {

useEffect(() => {
initChatWidget(document.body);
}, []);

return (
<section className={styles.features}>
<div className="container">
Expand Down
28 changes: 28 additions & 0 deletions src/theme/Layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, {useEffect} from "react";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this file?

import Layout from "@theme-original/Layout";

function CustomLayout(props) {
useEffect(() => {
const script = document.createElement("script");
script.src = "/js/casibase-tracker.js";
script.async = true;
document.body.appendChild(script);

script.onload = () => {
if (typeof window.initCasibaseChat === "function") {
window.initCasibaseChat({
endpoint: "https://ai.casbin.com",
themeColor: "rgb(64,59,121)",
});
}
};

return () => {
document.body.removeChild(script);
};
}, []);

return <Layout {...props} />;
}

export default CustomLayout;
5 changes: 5 additions & 0 deletions static/js/casibase-tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function() {
hsluoyz marked this conversation as resolved.
Show resolved Hide resolved
const script = document.createElement("script");
script.src = "https://tcdn.casibase.org/casibase.js";
document.head.appendChild(script);
})();
Loading