Skip to content

Commit

Permalink
feature(discovery): add Trieve search and AI chat to the docs (old Mi…
Browse files Browse the repository at this point in the history
…ntlify functionality)
  • Loading branch information
skeptrunedev committed Mar 6, 2025
1 parent e969dfe commit c643734
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 4 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/update-trieve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update Trieve

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

on:
push:
branches:
- main

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Trieve Fern Adapter
run: npm install -g trieve-vitepress-adapter

- name: Update Trieve Chunks
env:
TRIEVE_API_HOST: ${{ secrets.TRIEVE_API_HOST }}
TRIEVE_API_KEY: ${{ secrets.TRIEVE_API_KEY }}
TRIEVE_ORGANIZATION_ID: ${{ secrets.TRIEVE_ORGANIZATION_ID }}
TRIEVE_DATASET_TRACKING_ID: ${{ secrets.TRIEVE_DATASET_TRACKING_ID }}
run: trieve-vitepress-adapter --path . -s https://coolify.io/docs/openapi.json -r https://coolify.io -a docs/api-reference/api/operations
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ examples-temp
node_modules
pnpm-global
TODOs.md
*.timestamp-*.mjs
*.timestamp-*.mjs
.env
3 changes: 2 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default defineConfig({
['meta', { property: 'twitter:image', content: 'https://coolcdn.b-cdn.net/assets/coolify/og-image-docs.png' }],
['link', { rel: 'icon', href: 'coolify-logo-transparent.png' }],
['script', { src: 'https://analytics.coollabs.io/js/script.js', 'data-domain': 'coolify.io/docs' }],
['script', { async: 'true', src: 'trieve-user-script.js' }],
],
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
Expand Down Expand Up @@ -603,7 +604,7 @@ export default defineConfig({
plugins: [
yaml as any,
llms({
llmsDir: '/'
llmsDir: './'
})
],
assetsInclude: ['**/*.yml'],
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./tailwind.postcss";
import "vitepress-openapi/dist/style.css";

// @ts-ignore
import spec from '../../public/openapi.json' assert { type: 'json' }
import spec from "../../public/openapi.json" assert { type: "json" };

// Import components
import Card from "./components/Card.vue";
Expand All @@ -42,7 +42,7 @@ export default {
const openapi = useOpenapi({
spec,
base: "/docs/api-reference/api/operations/",
label: "API"
label: "API",
});

theme.enhanceApp({ app, openapi });
Expand Down
97 changes: 97 additions & 0 deletions docs/public/trieve-user-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ==UserScript==
// @name Coolify
// @namespace http://tampermonkey.net/
// @version 2025-01-16
// @description try to take over the world!
// @author You
// @match https://coolify.io/docs/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=coolify.io
// @grant none
// ==/UserScript==

const removeAllClickListeners = (element) => {
const newElement = element.cloneNode(true);
element.parentNode.replaceChild(newElement, element);
return newElement;
};

const makeDefaultSearchTrieve = async () => {
let defaultSearchBar = null;
let retries = 0;
while (!defaultSearchBar && retries < 10) {
for (const el of document.querySelectorAll("*")) {
if (el.querySelector('#local-search > button')) {
defaultSearchBar = el.querySelector('#local-search > button');
break;
}
}
retries++;
await new Promise((resolve) => setTimeout(resolve, 10));
}

if (!defaultSearchBar) {
return;
}

defaultSearchBar = removeAllClickListeners(defaultSearchBar);

defaultSearchBar.onclick = () => {
const event = new CustomEvent("trieve-open-with-text", {
detail: { text: "" },
});
window.dispatchEvent(event);
};
};

window.addEventListener('load', function() {
makeDefaultSearchTrieve();
});

const originalPushState = history.pushState;
history.pushState = function() {
originalPushState.apply(this, arguments);
makeDefaultSearchTrieve();
};


(async function () {
"use strict";
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://cdn.trieve.ai/beta/search-component/index.css";
document.head.appendChild(link);

import("https://cdn.trieve.ai/beta/search-component/vanilla/index.js").then(
async (module) => {
const { renderToDiv } = module;
const root = document.createElement("div");
root.classList.add("trigger");
document.body.appendChild(root);
const colorScheme = document.documentElement?.classList?.contains("dark")
? "dark"
: null;

renderToDiv(root, {
apiKey: "tr-4ge266qRg6AzfMAyWyqqUjmG3VC1CYYM",
datasetId: "cae68afa-93e1-4fb2-9945-693e65906409",
baseUrl: "https://api.trieve.ai",
type: "docs",
analytics: true,
theme: colorScheme === "dark" ? "dark" : null,
brandLogoImgSrcUrl: "https://coolify.io/docs/coolify-logo-transparent.png",
brandName: "Coolify",
brandColor: "#9664f3",
placeholder: "How can I help?",
defaultSearchQueries: ["Backups", "Postgresql", "Private NPM registry"],
defaultAiQuestions: ["How to fix expired GitHub personal access token (PAT)?", "My Raspberry Pi is crashing", "How to use Docker Compose?"],
defaultSearchMode: "search",
showFloatingButton: "true",
cssRelease: "none",
hideOpenButton: true,
});
},
(error) => {
console.error("Failed to load module:", error);
}
);
})();

0 comments on commit c643734

Please sign in to comment.