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 DocSearch config #35

Merged
merged 1 commit into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ p {
right: 0;
left: 0;
top: 0;
z-index: 999;
z-index: 99;
background-color: transparent;
border: 0;
-webkit-transition: all 0.5s ease;
Expand Down
43 changes: 43 additions & 0 deletions src/components/DocSearch.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
interface Props {
appId: string;
apiKey: string;
indexName: string;
container?: string;
language?: string;
debug?: boolean;
}

const {
appId="SOXMYGAM7C",
apiKey="64843cbaefbee8de62326b2ae47b8601",
indexName="nocobase",
container = '#docsearch',
language= 'en',
debug = false
} = Astro.props;
---

<script is:inline src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
<script
is:inline
type="text/javascript"
define:vars={{
appId,
apiKey,
indexName,
container,
language,
debug
}}
data-astro-rerun
>
docsearch({
appId: appId,
apiKey: apiKey,
indexName: indexName,
container: container,
language: language,
debug: debug
});
</script>
30 changes: 14 additions & 16 deletions src/layouts/BaseCN.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import ShapeFooter from "../components/ShapeFooter.astro";
import LanguageSwitcher from '../components/LanguageSwitcher.astro';
import DocSearch from "../components/DocSearch.astro";

const year = new Date().getFullYear();
const baseClassName = Astro.url.pathname.split("/")?.[2] || "";
Expand Down Expand Up @@ -296,6 +297,10 @@ const meta = {
</div>
</div>

<div class="menu-extras" style="margin-top: 20px">
<div id="docsearch"></div>
</div>

<div id="navigation">
<!-- Navigation Menu-->
<ul class="navigation-menu">
Expand Down Expand Up @@ -707,24 +712,17 @@ const meta = {
src="https://sibforms.com/forms/end-form/build/main.js"></script>
<!-- END Brevo Form -->

<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>

<script type="text/javascript">

docsearch({

appId: "SOXMYGAM7C",

apiKey: "64843cbaefbee8de62326b2ae47b8601",

indexName: "nocobase",

container: "### REPLACE ME WITH A CONTAINER (e.g. div) ###",

debug: false
<DocSearch/>
<script>
document.addEventListener("DOMContentLoaded", function() {
const searchButton = document.querySelector('.DocSearch-Button');
const placeholder = searchButton.querySelector('.DocSearch-Button-Placeholder');
const keys = searchButton.querySelector('.DocSearch-Button-Keys');

// 隐藏文本和快捷键
if (placeholder) placeholder.style.display = 'none';
if (keys) keys.style.display = 'none';
});

</script>
</body>
</html>
37 changes: 17 additions & 20 deletions src/layouts/BaseEN.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import ShapeFooter from "../components/ShapeFooter.astro";
import LanguageSwitcher from "../components/LanguageSwitcher.astro";
import DocSearch from "../components/DocSearch.astro";

const year = new Date().getFullYear();
const baseClassName = Astro.url.pathname.split("/")?.[2] || "";
Expand Down Expand Up @@ -257,6 +258,10 @@ const meta = {
</div>
</div>

<div class="menu-extras" style="margin-top: 20px">
<div id="docsearch"></div>
</div>

<div id="navigation">
<!-- Navigation Menu-->
<ul class="navigation-menu">
Expand Down Expand Up @@ -653,25 +658,17 @@ const meta = {
<script defer src="https://sibforms.com/forms/end-form/build/main.js"
></script>
<!-- END Brevo Form -->

<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>

<script type="text/javascript">

docsearch({

appId: "SOXMYGAM7C",

apiKey: "64843cbaefbee8de62326b2ae47b8601",

indexName: "nocobase",

container: "### REPLACE ME WITH A CONTAINER (e.g. div) ###",

debug: false

});

</script>
<DocSearch/>
<script>
document.addEventListener("DOMContentLoaded", function() {
const searchButton = document.querySelector('.DocSearch-Button');
const placeholder = searchButton.querySelector('.DocSearch-Button-Placeholder');
const keys = searchButton.querySelector('.DocSearch-Button-Keys');

// 隐藏文本和快捷键
if (placeholder) placeholder.style.display = 'none';
if (keys) keys.style.display = 'none';
});
</script>
</body>
</html>
30 changes: 14 additions & 16 deletions src/layouts/BaseJA.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import ShapeFooter from "../components/ShapeFooter.astro";
import LanguageSwitcher from "../components/LanguageSwitcher.astro";
import DocSearch from "../components/DocSearch.astro";

const year = new Date().getFullYear();
const baseClassName = Astro.url.pathname.split("/")?.[2] || "";
Expand Down Expand Up @@ -227,6 +228,10 @@ const meta = {
</div>
</div>

<div class="menu-extras" style="margin-top: 20px">
<div id="docsearch"></div>
</div>

<div id="navigation">
<!-- Navigation Menu-->
<ul class="navigation-menu">
Expand Down Expand Up @@ -609,24 +614,17 @@ const meta = {
src="https://sibforms.com/forms/end-form/build/main.js"></script>
<!-- END Brevo Form -->

<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>

<script type="text/javascript">

docsearch({

appId: "SOXMYGAM7C",

apiKey: "64843cbaefbee8de62326b2ae47b8601",

indexName: "nocobase",

container: "### REPLACE ME WITH A CONTAINER (e.g. div) ###",

debug: false
<DocSearch/>
<script>
document.addEventListener("DOMContentLoaded", function() {
const searchButton = document.querySelector('.DocSearch-Button');
const placeholder = searchButton.querySelector('.DocSearch-Button-Placeholder');
const keys = searchButton.querySelector('.DocSearch-Button-Keys');

// 隐藏文本和快捷键
if (placeholder) placeholder.style.display = 'none';
if (keys) keys.style.display = 'none';
});

</script>
</body>
</html>