Skip to content

Commit 5d20416

Browse files
docs: add algolia crawler for LS docs (#6570)
1 parent 6faee2f commit 5d20416

File tree

4 files changed

+164
-82
lines changed

4 files changed

+164
-82
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Algolia Indexer for HumanSignal Docs
2+
3+
on:
4+
push:
5+
branches: ["develop"]
6+
paths:
7+
- "docs/**"
8+
- ".github/workflows/algolia-crawler-hs-docs.yml"
9+
pull_request:
10+
branches:
11+
- develop
12+
13+
jobs:
14+
algolia_indexer:
15+
runs-on: ubuntu-latest
16+
env:
17+
APPLICATION_ID: "M7RXTHKYPM"
18+
API_KEY: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
19+
INDEX_NAME: "ghaction"
20+
CONFIG: >
21+
{"index_name": "ghaction",
22+
"stop_urls": ["https://docs.humansignal.com/guide/index.html", "https://docs.humansignal.com/guide/notion-faq.html", "https://labelstud.io/sdk/index.html"],
23+
"selectors_exclude": [".home-page-index"],
24+
"sitemap_urls": ["https://docs.humansignal.com/guide/sitemap-docs.xml", "https://labelstud.io/sitemap-blog.xml"],
25+
"selectors": {
26+
"default": {
27+
"lvl0": ".content h1, .ResourcesBannerHeading, .BlogTitle",
28+
"lvl1": ".content h2, .ResourcesContent h1, .ResourcesContent h2",
29+
"lvl2": ".content h3, .ResourcesContent h3",
30+
"lvl3": ".content h4, .ResourcesContent h4",
31+
"lvl4": ".content h5, .ResourcesContent h5",
32+
"lvl5": ".content h6, .ResourcesContent h6",
33+
"content": ".content-markdown > *, .ResourcesContent > .Text"
34+
}
35+
}
36+
}
37+
name: Index Algolia
38+
steps:
39+
- name: Algolia Docsearch Action
40+
id: algolia
41+
uses: adapttive/[email protected]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Algolia Indexer for Label Studio Docs
2+
3+
on:
4+
push:
5+
branches: ["develop"]
6+
paths:
7+
- "docs/**"
8+
- ".github/workflows/algolia-crawler-ls-docs.yml"
9+
pull_request:
10+
branches:
11+
- develop
12+
13+
jobs:
14+
algolia_indexer:
15+
runs-on: ubuntu-latest
16+
env:
17+
APPLICATION_ID: "M7RXTHKYPM"
18+
API_KEY: ${{ secrets.ALGOLIA_ADMIN_API_KEY }}
19+
INDEX_NAME: "labelstudiodocs"
20+
CONFIG: >
21+
{
22+
"index_name": "labelstudiodocs",
23+
"stop_urls": ["https://labelstud.io/guide/index.html", "https://labelstud.io/sdk/index.html"],
24+
"selectors_exclude": [".home-page-index"],
25+
"sitemap_urls": ["https://labelstud.io/sitemap-blog.xml", "https://labelstud.io/guide/sitemap-docs.xml"],
26+
"selectors": {
27+
"default": {
28+
"lvl0": ".content h1, .ResourcesBannerHeading, .BlogTitle",
29+
"lvl1": ".content h2, .ResourcesContent h1, .ResourcesContent h2",
30+
"lvl2": ".content h3, .ResourcesContent h3",
31+
"lvl3": ".content h4, .ResourcesContent h4",
32+
"lvl4": ".content h5, .ResourcesContent h5",
33+
"lvl5": ".content h6, .ResourcesContent h6",
34+
"content": ".content-markdown > *, .ResourcesContent > .Text"
35+
}
36+
}
37+
}
38+
name: Index Algolia
39+
steps:
40+
- name: Algolia Docsearch Action
41+
id: algolia
42+
uses: adapttive/[email protected]

.github/workflows/algolia-crawler.yml

-35
This file was deleted.

docs/themes/v2/source/js/header.js

+81-47
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
(function() {
1+
(function () {
22
const pageHeader = document.querySelector(".page-header");
33
const pageSidebar = document.querySelector(".page-sidebar");
44
const navToggleButtons = pageHeader.querySelectorAll("button");
5-
const sideBarToggleButtons = pageSidebar && pageSidebar.querySelectorAll("button");
5+
const sideBarToggleButtons =
6+
pageSidebar && pageSidebar.querySelectorAll("button");
67
const hamburgerButton = pageHeader.querySelector(".hamburger-button");
78

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

15-
arrow.style.setProperty('transform', arrowStyles.transform === "none" ? "matrix(-1, 0, 0, -1, 0, 0)" : "none");
16-
menu.style.setProperty('display', menuStyles.display === "flex" ? "none" : "flex");
17-
}
18-
19-
navToggleButtons && navToggleButtons.forEach(button => button.addEventListener("click", toggleMenu));
20-
sideBarToggleButtons && sideBarToggleButtons.forEach(button => button.addEventListener("click", toggleMenu));
21-
22-
const githubstarsContainer = document.querySelector(".github-stars-count");
23-
24-
if(githubstarsContainer) {
16+
arrow.style.setProperty(
17+
"transform",
18+
arrowStyles.transform === "none" ? "matrix(-1, 0, 0, -1, 0, 0)" : "none"
19+
);
20+
menu.style.setProperty(
21+
"display",
22+
menuStyles.display === "flex" ? "none" : "flex"
23+
);
24+
};
25+
26+
navToggleButtons &&
27+
navToggleButtons.forEach((button) =>
28+
button.addEventListener("click", toggleMenu)
29+
);
30+
sideBarToggleButtons &&
31+
sideBarToggleButtons.forEach((button) =>
32+
button.addEventListener("click", toggleMenu)
33+
);
34+
35+
const githubstarsContainer = document.querySelector(".github-stars-count");
36+
37+
if (githubstarsContainer) {
2538
fetch("https://api.github.com/repos/heartexlabs/label-studio")
26-
.then((response) => response.json()
27-
.then((data) => {
28-
let stars = "";
29-
if(data.stargazers_count) stars = data.stargazers_count.toLocaleString('en-US')
30-
if(stars) githubstarsContainer.textContent = stars;
31-
}))
32-
.catch((err) => {
33-
console.log(err)
34-
});
39+
.then((response) =>
40+
response.json().then((data) => {
41+
let stars = "";
42+
if (data.stargazers_count)
43+
stars = data.stargazers_count.toLocaleString("en-US");
44+
if (stars) githubstarsContainer.textContent = stars;
45+
})
46+
)
47+
.catch((err) => {
48+
console.log(err);
49+
});
3550
}
3651

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

4055
const siteVersion = searchInput.dataset.siteVersion;
4156

42-
const appId = siteVersion == "enterprise" ? 'M7RXTHKYPM' : "HELLEDAKPT";
43-
const apiKey = siteVersion == "enterprise" ? '8ed23cbc92e0806140603fb62236efee' : '1d0410ef855a968fbc40669df1c4a73e'
44-
const indexName = siteVersion == "enterprise" ? 'ghaction' : 'labelstud'
45-
46-
if(searchInput) {
57+
const appId = "M7RXTHKYPM";
58+
const apiKey = "8ed23cbc92e0806140603fb62236efee";
59+
const indexName =
60+
siteVersion == "enterprise" ? "ghaction" : "labelstudiodocs";
4761

62+
if (searchInput) {
4863
window.docsearch({
49-
container: '#docsearch-input',
50-
inputSelector: '#docsearch-input',
64+
container: "#docsearch-input",
65+
inputSelector: "#docsearch-input",
5166
appId,
5267
apiKey,
5368
indexName,
5469
algoliaOptions: { hitsPerPage: 10 },
5570
});
56-
71+
5772
const handleFocusSearch = (e) => {
58-
if (document.activeElement.localName === 'body' && e.code !== "Space" && e.code !== "MetaLeft" && !e.altKey && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
73+
if (
74+
document.activeElement.localName === "body" &&
75+
e.code !== "Space" &&
76+
e.code !== "MetaLeft" &&
77+
!e.altKey &&
78+
!e.shiftKey &&
79+
!e.ctrlKey &&
80+
!e.metaKey
81+
) {
5982
searchInput.focus();
6083
}
6184

62-
if(document.activeElement.localName === 'body' && e.code === "KeyK" && (e.metaKey || e.ctrlKey)) {
85+
if (
86+
document.activeElement.localName === "body" &&
87+
e.code === "KeyK" &&
88+
(e.metaKey || e.ctrlKey)
89+
) {
6390
searchInput.focus();
6491
}
65-
}
66-
92+
};
93+
6794
window.addEventListener("keydown", handleFocusSearch);
6895
}
6996
});
@@ -74,26 +101,33 @@
74101

75102
hamburgerButton.classList.toggle("active");
76103

77-
nav.style.setProperty('display', navStyle.display=== "flex" ? "none" : "flex");
78-
79-
})
104+
nav.style.setProperty(
105+
"display",
106+
navStyle.display === "flex" ? "none" : "flex"
107+
);
108+
});
80109

81-
if (window.matchMedia( "(hover: none)" ).matches) {
110+
if (window.matchMedia("(hover: none)").matches) {
82111
const toggleQuickNav = (e) => {
83-
if (e.target.tagName.toLowerCase() !== 'a') {
112+
if (e.target.tagName.toLowerCase() !== "a") {
84113
const component = e.currentTarget;
85114
const menu = component.querySelector("ul");
86115
const menuStyles = getComputedStyle(menu);
87116

88-
menu.style.setProperty('display', menuStyles.display=== "flex" ? "none" : "flex");
117+
menu.style.setProperty(
118+
"display",
119+
menuStyles.display === "flex" ? "none" : "flex"
120+
);
89121
}
90-
}
91-
92-
const toggleQuicNavButton = document.querySelector(".page-header-content-switcher");
93-
toggleQuicNavButton.addEventListener("click", toggleQuickNav)
94-
}
122+
};
123+
124+
const toggleQuicNavButton = document.querySelector(
125+
".page-header-content-switcher"
126+
);
127+
toggleQuicNavButton.addEventListener("click", toggleQuickNav);
128+
}
95129

96-
pageSidebar.addEventListener('scroll', function() {
97-
localStorage.setItem('labelstudio_scrollPosition', this.scrollTop);
130+
pageSidebar.addEventListener("scroll", function () {
131+
localStorage.setItem("labelstudio_scrollPosition", this.scrollTop);
98132
});
99133
})();

0 commit comments

Comments
 (0)