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

docs: add algolia crawler for LS docs #6570

Merged
merged 28 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions .github/workflows/algolia-crawler-hs-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Algolia Indexer for HumanSignal Docs

on:
push:
branches: ["develop"]
paths:
- "docs/**"
- ".github/workflows/algolia-crawler-hs-docs.yml"
pull_request:
branches:
- develop

jobs:
algolia_indexer:
runs-on: ubuntu-latest
env:
APPLICATION_ID: "M7RXTHKYPM"
API_KEY: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
INDEX_NAME: "ghaction"
CONFIG: >
{"index_name": "ghaction",
"stop_urls": ["https://docs.humansignal.com/guide/index.html", "https://docs.humansignal.com/guide/notion-faq.html", "https://labelstud.io/sdk/index.html"],
"selectors_exclude": [".home-page-index"],
"sitemap_urls": ["https://docs.humansignal.com/guide/sitemap-docs.xml", "https://labelstud.io/sitemap-blog.xml"],
"selectors": {
"default": {
"lvl0": ".content h1, .ResourcesBannerHeading, .BlogTitle",
"lvl1": ".content h2, .ResourcesContent h1, .ResourcesContent h2",
"lvl2": ".content h3, .ResourcesContent h3",
"lvl3": ".content h4, .ResourcesContent h4",
"lvl4": ".content h5, .ResourcesContent h5",
"lvl5": ".content h6, .ResourcesContent h6",
"content": ".content-markdown > *, .ResourcesContent > .Text"
}
}
}
name: Index Algolia
steps:
- name: Algolia Docsearch Action
id: algolia
uses: adapttive/[email protected]
42 changes: 42 additions & 0 deletions .github/workflows/algolia-crawler-ls-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Algolia Indexer for Label Studio Docs

on:
push:
branches: ["develop"]
paths:
- "docs/**"
- ".github/workflows/algolia-crawler-ls-docs.yml"
pull_request:
branches:
- develop

jobs:
algolia_indexer:
runs-on: ubuntu-latest
env:
APPLICATION_ID: "M7RXTHKYPM"
API_KEY: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
INDEX_NAME: "labelstudiodocs"
CONFIG: >
{
"index_name": "labelstudiodocs",
"stop_urls": ["https://labelstud.io/guide/index.html", "https://labelstud.io/sdk/index.html"],
"selectors_exclude": [".home-page-index"],
"sitemap_urls": ["https://labelstud.io/sitemap-blog.xml", "https://labelstud.io/guide/sitemap-docs.xml"],
"selectors": {
"default": {
"lvl0": ".content h1, .ResourcesBannerHeading, .BlogTitle",
"lvl1": ".content h2, .ResourcesContent h1, .ResourcesContent h2",
"lvl2": ".content h3, .ResourcesContent h3",
"lvl3": ".content h4, .ResourcesContent h4",
"lvl4": ".content h5, .ResourcesContent h5",
"lvl5": ".content h6, .ResourcesContent h6",
"content": ".content-markdown > *, .ResourcesContent > .Text"
}
}
}
name: Index Algolia
steps:
- name: Algolia Docsearch Action
id: algolia
uses: adapttive/[email protected]
35 changes: 0 additions & 35 deletions .github/workflows/algolia-crawler.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ theme: v2

sitemap:
path:
- sitemap-docs.xml
- guide/sitemap-docs.xml

search:
path: search.xml
Expand Down
128 changes: 81 additions & 47 deletions docs/themes/v2/source/js/header.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(function() {
(function () {
const pageHeader = document.querySelector(".page-header");
const pageSidebar = document.querySelector(".page-sidebar");
const navToggleButtons = pageHeader.querySelectorAll("button");
const sideBarToggleButtons = pageSidebar && pageSidebar.querySelectorAll("button");
const sideBarToggleButtons =
pageSidebar && pageSidebar.querySelectorAll("button");
const hamburgerButton = pageHeader.querySelector(".hamburger-button");

const toggleMenu = (e) => {
Expand All @@ -12,58 +13,84 @@
const arrow = button.querySelector("svg");
const arrowStyles = getComputedStyle(arrow);

arrow.style.setProperty('transform', arrowStyles.transform === "none" ? "matrix(-1, 0, 0, -1, 0, 0)" : "none");
menu.style.setProperty('display', menuStyles.display === "flex" ? "none" : "flex");
}

navToggleButtons && navToggleButtons.forEach(button => button.addEventListener("click", toggleMenu));
sideBarToggleButtons && sideBarToggleButtons.forEach(button => button.addEventListener("click", toggleMenu));

const githubstarsContainer = document.querySelector(".github-stars-count");

if(githubstarsContainer) {
arrow.style.setProperty(
"transform",
arrowStyles.transform === "none" ? "matrix(-1, 0, 0, -1, 0, 0)" : "none"
);
menu.style.setProperty(
"display",
menuStyles.display === "flex" ? "none" : "flex"
);
};

navToggleButtons &&
navToggleButtons.forEach((button) =>
button.addEventListener("click", toggleMenu)
);
sideBarToggleButtons &&
sideBarToggleButtons.forEach((button) =>
button.addEventListener("click", toggleMenu)
);

const githubstarsContainer = document.querySelector(".github-stars-count");

if (githubstarsContainer) {
fetch("https://api.github.com/repos/heartexlabs/label-studio")
.then((response) => response.json()
.then((data) => {
let stars = "";
if(data.stargazers_count) stars = data.stargazers_count.toLocaleString('en-US')
if(stars) githubstarsContainer.textContent = stars;
}))
.catch((err) => {
console.log(err)
});
.then((response) =>
response.json().then((data) => {
let stars = "";
if (data.stargazers_count)
stars = data.stargazers_count.toLocaleString("en-US");
if (stars) githubstarsContainer.textContent = stars;
})
)
.catch((err) => {
console.log(err);
});
}

window.addEventListener('load', (event) => {
window.addEventListener("load", (event) => {
const searchInput = document.querySelector("#docsearch-input");

const siteVersion = searchInput.dataset.siteVersion;

const appId = siteVersion == "enterprise" ? 'M7RXTHKYPM' : "HELLEDAKPT";
const apiKey = siteVersion == "enterprise" ? '8ed23cbc92e0806140603fb62236efee' : '1d0410ef855a968fbc40669df1c4a73e'
const indexName = siteVersion == "enterprise" ? 'ghaction' : 'labelstud'

if(searchInput) {
const appId = "M7RXTHKYPM";
const apiKey = "8ed23cbc92e0806140603fb62236efee";
const indexName =
siteVersion == "enterprise" ? "ghaction" : "labelstudiodocs";

if (searchInput) {
window.docsearch({
container: '#docsearch-input',
inputSelector: '#docsearch-input',
container: "#docsearch-input",
inputSelector: "#docsearch-input",
appId,
apiKey,
indexName,
algoliaOptions: { hitsPerPage: 10 },
});

const handleFocusSearch = (e) => {
if (document.activeElement.localName === 'body' && e.code !== "Space" && e.code !== "MetaLeft" && !e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
if (
document.activeElement.localName === "body" &&
e.code !== "Space" &&
e.code !== "MetaLeft" &&
!e.altKey &&
!e.shiftKey &&
!e.ctrlKey &&
!e.metaKey
) {
searchInput.focus();
}

if(document.activeElement.localName === 'body' && e.code === "KeyK" && (e.metaKey || e.ctrlKey)) {
if (
document.activeElement.localName === "body" &&
e.code === "KeyK" &&
(e.metaKey || e.ctrlKey)
) {
searchInput.focus();
}
}
};

window.addEventListener("keydown", handleFocusSearch);
}
});
Expand All @@ -74,26 +101,33 @@

hamburgerButton.classList.toggle("active");

nav.style.setProperty('display', navStyle.display=== "flex" ? "none" : "flex");

})
nav.style.setProperty(
"display",
navStyle.display === "flex" ? "none" : "flex"
);
});

if (window.matchMedia( "(hover: none)" ).matches) {
if (window.matchMedia("(hover: none)").matches) {
const toggleQuickNav = (e) => {
if (e.target.tagName.toLowerCase() !== 'a') {
if (e.target.tagName.toLowerCase() !== "a") {
const component = e.currentTarget;
const menu = component.querySelector("ul");
const menuStyles = getComputedStyle(menu);

menu.style.setProperty('display', menuStyles.display=== "flex" ? "none" : "flex");
menu.style.setProperty(
"display",
menuStyles.display === "flex" ? "none" : "flex"
);
}
}

const toggleQuicNavButton = document.querySelector(".page-header-content-switcher");
toggleQuicNavButton.addEventListener("click", toggleQuickNav)
}
};

const toggleQuicNavButton = document.querySelector(
".page-header-content-switcher"
);
toggleQuicNavButton.addEventListener("click", toggleQuickNav);
}

pageSidebar.addEventListener('scroll', function() {
localStorage.setItem('labelstudio_scrollPosition', this.scrollTop);
pageSidebar.addEventListener("scroll", function () {
localStorage.setItem("labelstudio_scrollPosition", this.scrollTop);
});
})();