Docs cn #1
+11
@@ -5,3 +5,14 @@ _site
|
||||
Gemfile.lock
|
||||
.idea
|
||||
.jekyll-cache
|
||||
/opensearch-docs-cn.iml
|
||||
|
||||
# VitePress(文档工具链安装在 .vitepress/node_modules,构建产物不入库)
|
||||
/site/
|
||||
/.vitepress/node_modules/
|
||||
# 指向 .vitepress/node_modules 的软链接(见 Jenkinsfile Install 阶段)
|
||||
/node_modules
|
||||
/.vitepress/cache/
|
||||
/.vitepress/dist/
|
||||
/.vitepress/generated/
|
||||
/.wrangler/
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig, type DefaultTheme, type LocaleConfig } from 'vitepress';
|
||||
|
||||
type GeneratedLocale = {
|
||||
label: string;
|
||||
base: string;
|
||||
sidebar: DefaultTheme.SidebarMulti;
|
||||
};
|
||||
|
||||
const siteFile = path.join(path.dirname(fileURLToPath(import.meta.url)), 'generated', 'site.json');
|
||||
if (!fs.existsSync(siteFile))
|
||||
throw new Error('Run "node scripts/generate.mjs" first. The file .vitepress/generated/site.json is missing.');
|
||||
const site: { locales: Record<string, GeneratedLocale> } = JSON.parse(fs.readFileSync(siteFile, 'utf8'));
|
||||
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const englishSrcDir = path.join(rootDir, 'src');
|
||||
|
||||
const EN_PREFIX = '/en';
|
||||
const FORUM_URL = 'https://www.isharkfly.com/tag/opensearch';
|
||||
const CONTACT_URL = 'https://www.isharkfly.com/t/opensearch/15530';
|
||||
const REPO_URL = 'https://github.com/iSharkFly-Docs/opensearch-docs-cn';
|
||||
|
||||
// Sidebar group names (just-the-docs collection names from _config.yml).
|
||||
const zhSidebarText: Record<string, string> = {
|
||||
'About OpenSearch': '关于 OpenSearch',
|
||||
'Install and upgrade': '安装与升级',
|
||||
'Migrate to OpenSearch': '迁移到 OpenSearch',
|
||||
'Managing Indexes': '索引管理',
|
||||
'Ingest Pipelines': '摄取管道',
|
||||
'OpenSearch Integrations': 'OpenSearch 集成',
|
||||
'Creating and tuning your cluster': '创建与调优集群',
|
||||
'Security in OpenSearch': 'OpenSearch 安全',
|
||||
'Security analytics': '安全分析',
|
||||
'Mappings and field types': '映射与字段类型',
|
||||
'Text analysis': '文本分析',
|
||||
'Aggregations': '聚合',
|
||||
'Search': '搜索',
|
||||
'Machine learning': '机器学习',
|
||||
'Automating configurations': '自动化配置',
|
||||
'Monitoring your cluster': '监控集群',
|
||||
'Observability': '可观测性',
|
||||
'Reporting': '报告',
|
||||
'Tools': '工具',
|
||||
'API reference': 'API 参考',
|
||||
'Troubleshooting': '故障排查',
|
||||
'Developer documentation': '开发者文档',
|
||||
'Clients': '客户端',
|
||||
};
|
||||
|
||||
// Sections with their own sidebar; everything else belongs to the main docs.
|
||||
const SECTION_PATHS = '(?:clients|benchmark|data-prepper|api-reference|en)/';
|
||||
|
||||
function enLink(link: string) {
|
||||
return link.startsWith('/') ? EN_PREFIX + link : link;
|
||||
}
|
||||
|
||||
function mapSidebar(
|
||||
sidebar: DefaultTheme.SidebarMulti,
|
||||
mapLink: (link: string) => string,
|
||||
mapGroupText: (text: string) => string,
|
||||
): DefaultTheme.SidebarMulti {
|
||||
const mapItems = (items: DefaultTheme.SidebarItem[]): DefaultTheme.SidebarItem[] => items.map(item => ({
|
||||
...item,
|
||||
...(item.items ? { text: mapGroupText(item.text ?? ''), items: mapItems(item.items) } : {}),
|
||||
...(item.link ? { link: mapLink(item.link) } : {}),
|
||||
}));
|
||||
return Object.fromEntries(Object.entries(sidebar).map(([key, value]) => [
|
||||
mapLink(key),
|
||||
Array.isArray(value) ? mapItems(value) : { ...value, base: mapLink(value.base), items: mapItems(value.items) },
|
||||
]));
|
||||
}
|
||||
|
||||
const zhThemeText: DefaultTheme.Config = {
|
||||
outline: { level: [2, 3], label: '本页目录' },
|
||||
docFooter: { prev: '上一页', next: '下一页' },
|
||||
darkModeSwitchLabel: '外观',
|
||||
lightModeSwitchTitle: '切换到浅色模式',
|
||||
darkModeSwitchTitle: '切换到深色模式',
|
||||
sidebarMenuLabel: '菜单',
|
||||
returnToTopLabel: '回到顶部',
|
||||
langMenuLabel: '切换语言',
|
||||
skipToContentLabel: '跳到正文',
|
||||
notFound: {
|
||||
title: '页面未找到',
|
||||
quote: '你要找的页面不存在,或者已经被移动。',
|
||||
linkLabel: '返回首页',
|
||||
linkText: '返回首页',
|
||||
},
|
||||
footer: {
|
||||
message: `基于 Apache License 2.0 发布。<a href="${FORUM_URL}">OpenSearch 中文论坛</a> · <a href="${CONTACT_URL}">联系我们</a>`,
|
||||
copyright: 'Copyright © OpenSearch contributors',
|
||||
},
|
||||
};
|
||||
|
||||
const zhSearchText = {
|
||||
button: { buttonText: '搜索', buttonAriaLabel: '搜索' },
|
||||
modal: {
|
||||
displayDetails: '显示详细列表',
|
||||
resetButtonTitle: '清除查询',
|
||||
backButtonTitle: '关闭搜索',
|
||||
noResultsText: '没有找到结果',
|
||||
footer: {
|
||||
selectText: '选择',
|
||||
selectKeyAriaLabel: '回车',
|
||||
navigateText: '切换',
|
||||
navigateUpKeyAriaLabel: '向上',
|
||||
navigateDownKeyAriaLabel: '向下',
|
||||
closeText: '关闭',
|
||||
closeKeyAriaLabel: 'Esc',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const zhLocales: LocaleConfig<DefaultTheme.Config> = {};
|
||||
const enLocales: LocaleConfig<DefaultTheme.Config> = {};
|
||||
|
||||
for (const [key, locale] of Object.entries(site.locales)) {
|
||||
const b = locale.base;
|
||||
zhLocales[key] = {
|
||||
label: `简体中文`,
|
||||
lang: 'zh-CN',
|
||||
link: b,
|
||||
title: 'OpenSearch',
|
||||
description: `OpenSearch 中文文档`,
|
||||
themeConfig: {
|
||||
...zhThemeText,
|
||||
nav: [
|
||||
{ text: '文档', link: `${b}about/`, activeMatch: `^${b}(?!${SECTION_PATHS})[^/]+` },
|
||||
{ text: 'API 参考', link: `${b}api-reference/`, activeMatch: `^${b}api-reference/` },
|
||||
{ text: '客户端', link: `${b}clients/`, activeMatch: `^${b}clients/` },
|
||||
{ text: 'Data Prepper', link: `${b}data-prepper/`, activeMatch: `^${b}data-prepper/` },
|
||||
{ text: 'Benchmark', link: `${b}benchmark/`, activeMatch: `^${b}benchmark/` },
|
||||
{ text: '中文论坛', link: FORUM_URL },
|
||||
],
|
||||
sidebar: mapSidebar(locale.sidebar, link => link, text => zhSidebarText[text] ?? text),
|
||||
},
|
||||
};
|
||||
|
||||
const enBase = enLink(b);
|
||||
enLocales[key === 'root' ? 'en' : `en/${key}`] = {
|
||||
label: `English`,
|
||||
lang: 'en-US',
|
||||
link: enBase,
|
||||
title: 'OpenSearch',
|
||||
description: `OpenSearch documentation`,
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Docs', link: `${enBase}about/`, activeMatch: `^${enBase}(?!${SECTION_PATHS})[^/]+` },
|
||||
{ text: 'API reference', link: `${enBase}api-reference/`, activeMatch: `^${enBase}api-reference/` },
|
||||
{ text: 'Clients', link: `${enBase}clients/`, activeMatch: `^${enBase}clients/` },
|
||||
{ text: 'Data Prepper', link: `${enBase}data-prepper/`, activeMatch: `^${enBase}data-prepper/` },
|
||||
{ text: 'Benchmark', link: `${enBase}benchmark/`, activeMatch: `^${enBase}benchmark/` },
|
||||
{ text: 'Forum', link: FORUM_URL },
|
||||
],
|
||||
sidebar: mapSidebar(locale.sidebar, enLink, text => text),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const locales: LocaleConfig<DefaultTheme.Config> = { ...zhLocales };
|
||||
for (const key of Object.keys(enLocales).sort((a, b) => b.length - a.length))
|
||||
locales[key] = enLocales[key];
|
||||
|
||||
function listPages(dir: string, rel = ''): string[] {
|
||||
if (!fs.existsSync(dir))
|
||||
return [];
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
||||
const entryRel = rel + entry.name;
|
||||
if (entry.isDirectory()) {
|
||||
if (!rel && (['zh', 'en', 'public'].includes(entry.name) || site.locales[entry.name]))
|
||||
return [];
|
||||
return listPages(path.join(dir, entry.name), `${entryRel}/`);
|
||||
}
|
||||
return entry.name.endsWith('.md') ? [entryRel] : [];
|
||||
});
|
||||
}
|
||||
|
||||
const pagesByLanguage = Object.fromEntries(Object.keys(site.locales).map(key => [
|
||||
key,
|
||||
listPages(key === 'root' ? englishSrcDir : path.join(englishSrcDir, key)),
|
||||
]));
|
||||
|
||||
// Tags the docs write as HTML. Anything else that looks like a tag in the text
|
||||
// (such as <index> or <node-id> placeholders) is shown literally instead of being
|
||||
// compiled by Vue.
|
||||
const HTML_TAGS = new Set((
|
||||
'a abbr audio b badge big blockquote br button caption center cite code col colgroup dd del details dfn div dl dt '
|
||||
+ 'em figcaption figure font h1 h2 h3 h4 h5 h6 header hr i iframe img input ins kbd label li mark nobr ol option p '
|
||||
+ 'picture pre q s samp section select small source span strong style sub summary sup svg table tbody td '
|
||||
+ 'textarea tfoot th thead tr tt u ul var video wbr'
|
||||
).split(' '));
|
||||
|
||||
function isKnownTag(html: string) {
|
||||
const m = html.match(/^<\/?([A-Za-z][\w-]*)/);
|
||||
return !m || HTML_TAGS.has(m[1]) || m[1] === 'Badge';
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
srcDir: 'site',
|
||||
lang: 'zh-CN',
|
||||
title: 'OpenSearch',
|
||||
description: 'OpenSearch 中文文档',
|
||||
cleanUrls: true,
|
||||
lastUpdated: false,
|
||||
ignoreDeadLinks: true,
|
||||
locales,
|
||||
head: [
|
||||
['link', { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' }],
|
||||
['link', { rel: 'alternate icon', href: '/favicon.png', type: 'image/png' }],
|
||||
// Google Tag Manager
|
||||
['script', {}, `(function (w, d, s, l, i) {
|
||||
w[l] = w[l] || [];
|
||||
w[l].push({
|
||||
'gtm.start':
|
||||
new Date().getTime(), event: 'gtm.js'
|
||||
});
|
||||
var f = d.getElementsByTagName(s)[0],
|
||||
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
|
||||
j.async = true;
|
||||
j.src =
|
||||
'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
|
||||
f.parentNode.insertBefore(j, f);
|
||||
})(window, document, 'script', 'dataLayer', 'GTM-W3NL9V');`],
|
||||
// End Google Tag Manager
|
||||
],
|
||||
markdown: {
|
||||
theme: { light: 'github-light', dark: 'github-dark' },
|
||||
config: md => {
|
||||
const defaultCodeInline = md.renderer.rules.code_inline!;
|
||||
md.renderer.rules.code_inline = (tokens, idx, options, env, self) =>
|
||||
defaultCodeInline(tokens, idx, options, env, self).replace(/^<code/, '<code v-pre');
|
||||
const defaultText = md.renderer.rules.text!;
|
||||
md.renderer.rules.text = (tokens, idx, options, env, self) =>
|
||||
defaultText(tokens, idx, options, env, self).replace(/\{\{/g, '{{').replace(/\}\}/g, '}}');
|
||||
md.renderer.rules.html_inline = (tokens, idx) =>
|
||||
isKnownTag(tokens[idx].content) ? tokens[idx].content : md.utils.escapeHtml(tokens[idx].content);
|
||||
const defaultHtmlBlock = md.renderer.rules.html_block!;
|
||||
md.renderer.rules.html_block = (tokens, idx, options, env, self) =>
|
||||
isKnownTag(tokens[idx].content.trimStart())
|
||||
? defaultHtmlBlock(tokens, idx, options, env, self)
|
||||
: `<p>${md.utils.escapeHtml(tokens[idx].content)}</p>`;
|
||||
},
|
||||
},
|
||||
themeConfig: {
|
||||
logo: '/favicon.svg',
|
||||
search: {
|
||||
provider: 'local',
|
||||
options: {
|
||||
locales: Object.fromEntries(Object.keys(zhLocales).map(key => [key, { translations: zhSearchText }])),
|
||||
},
|
||||
},
|
||||
outline: { level: [2, 3] },
|
||||
socialLinks: [
|
||||
{ icon: 'github', link: REPO_URL },
|
||||
],
|
||||
editLink: undefined,
|
||||
footer: {
|
||||
message: `Released under the Apache License 2.0. <a href="${FORUM_URL}">Forum</a> · <a href="${CONTACT_URL}">Contact us</a>`,
|
||||
copyright: 'Copyright © OpenSearch contributors',
|
||||
},
|
||||
languageSwitcher: {
|
||||
enPrefix: EN_PREFIX,
|
||||
pages: pagesByLanguage,
|
||||
},
|
||||
} as DefaultTheme.Config,
|
||||
vite: {
|
||||
build: { chunkSizeWarningLimit: 4096 },
|
||||
// Some docs images use upper-case extensions (apply-policy.PNG).
|
||||
assetsInclude: [/\.(PNG|JPE?G|GIF|SVG)$/],
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: /^.*\/VPNavBarTranslations\.vue$/,
|
||||
replacement: fileURLToPath(new URL('./theme/components/NavBarLanguageSwitcher.vue', import.meta.url)),
|
||||
},
|
||||
{
|
||||
find: /^.*\/VPNavScreenTranslations\.vue$/,
|
||||
replacement: fileURLToPath(new URL('./theme/components/NavScreenLanguageSwitcher.vue', import.meta.url)),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue';
|
||||
import { VPLink } from 'vitepress/theme';
|
||||
import { useLanguageSwitcher } from '../languageSwitcher';
|
||||
|
||||
const { readingLanguages, labels } = useLanguageSwitcher();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VPFlyout class="NavBarLanguageSwitcher" icon="vpi-languages" :label="labels.menu">
|
||||
<div class="items">
|
||||
<p class="title">{{ labels.reading }}</p>
|
||||
<VPLink
|
||||
v-for="item in readingLanguages"
|
||||
:key="item.text"
|
||||
class="link"
|
||||
:class="{ active: item.active }"
|
||||
:href="item.link"
|
||||
:lang="item.lang"
|
||||
:hreflang="item.lang"
|
||||
rel="alternate"
|
||||
>{{ item.text }}</VPLink>
|
||||
</div>
|
||||
</VPFlyout>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.NavBarLanguageSwitcher {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 1280px) {
|
||||
.NavBarLanguageSwitcher {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.items {
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.title {
|
||||
padding: 0 12px;
|
||||
line-height: 32px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.link {
|
||||
display: block;
|
||||
border-radius: 6px;
|
||||
padding: 0 12px;
|
||||
line-height: 32px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-text-1);
|
||||
white-space: nowrap;
|
||||
transition: background-color 0.25s, color 0.25s;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
color: var(--vp-c-brand-1);
|
||||
background-color: var(--vp-c-default-soft);
|
||||
}
|
||||
|
||||
.link.active {
|
||||
color: var(--vp-c-brand-1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { VPLink } from 'vitepress/theme';
|
||||
import { useLanguageSwitcher } from '../languageSwitcher';
|
||||
|
||||
const { readingLanguages, labels, currentLabel } = useLanguageSwitcher();
|
||||
const isOpen = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="NavScreenLanguageSwitcher" :class="{ open: isOpen }">
|
||||
<button class="toggle" :aria-expanded="isOpen" @click="isOpen = !isOpen">
|
||||
<span class="vpi-languages icon lang" />
|
||||
{{ currentLabel }}
|
||||
<span class="vpi-chevron-down icon chevron" />
|
||||
</button>
|
||||
|
||||
<div class="groups">
|
||||
<p class="title">{{ labels.reading }}</p>
|
||||
<ul class="list">
|
||||
<li v-for="item in readingLanguages" :key="item.text">
|
||||
<VPLink class="link" :class="{ active: item.active }" :href="item.link" :lang="item.lang">
|
||||
{{ item.text }}
|
||||
</VPLink>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.NavScreenLanguageSwitcher {
|
||||
height: 24px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.NavScreenLanguageSwitcher.open {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.icon.lang {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.icon.chevron {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.groups {
|
||||
padding: 4px 0 0 24px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.list {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
.link {
|
||||
line-height: 32px;
|
||||
font-size: 13px;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.link.active {
|
||||
color: var(--vp-c-brand-1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useData } from 'vitepress';
|
||||
|
||||
const { frontmatter, page } = useData();
|
||||
const englishLink = computed(() =>
|
||||
'/en/' + page.value.relativePath.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, ''));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="frontmatter.untranslated" class="untranslated-notice" lang="zh-CN">
|
||||
本页尚未翻译成中文,以下为英文原文。
|
||||
<a :href="englishLink">查看英文版</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.untranslated-notice {
|
||||
margin: 0 0 24px;
|
||||
border: 1px solid var(--vp-custom-block-info-border);
|
||||
border-radius: 8px;
|
||||
padding: 12px 16px;
|
||||
font-size: 14px;
|
||||
line-height: 24px;
|
||||
color: var(--vp-custom-block-info-text);
|
||||
background-color: var(--vp-custom-block-info-bg);
|
||||
}
|
||||
|
||||
.untranslated-notice a {
|
||||
font-weight: 500;
|
||||
color: var(--vp-c-brand-1);
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,23 @@
|
||||
:root {
|
||||
--vp-c-brand-1: #005eb8;
|
||||
--vp-c-brand-2: #0070d9;
|
||||
--vp-c-brand-3: #004a91;
|
||||
--vp-c-brand-soft: rgba(0, 94, 184, 0.14);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-brand-1: #00a3e0;
|
||||
--vp-c-brand-2: #33b5e6;
|
||||
--vp-c-brand-3: #0082b3;
|
||||
--vp-c-brand-soft: rgba(0, 163, 224, 0.16);
|
||||
}
|
||||
|
||||
.vp-doc img {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* Wide API parameter tables scroll instead of squeezing the text. */
|
||||
.vp-doc table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { h } from 'vue';
|
||||
import DefaultTheme from 'vitepress/theme';
|
||||
import type { Theme } from 'vitepress';
|
||||
import UntranslatedNotice from './components/UntranslatedNotice.vue';
|
||||
import './custom.css';
|
||||
|
||||
export default {
|
||||
extends: DefaultTheme,
|
||||
Layout: () => h(DefaultTheme.Layout, null, {
|
||||
'doc-before': () => h(UntranslatedNotice),
|
||||
}),
|
||||
} satisfies Theme;
|
||||
@@ -0,0 +1,58 @@
|
||||
import { computed } from 'vue';
|
||||
import { useData } from 'vitepress';
|
||||
|
||||
type SwitcherConfig = {
|
||||
enPrefix: string;
|
||||
pages: Record<string, string[]>;
|
||||
};
|
||||
|
||||
export type SwitcherLink = { text: string; link: string; lang?: string; active: boolean };
|
||||
|
||||
const READING_LANGUAGES = [
|
||||
{ key: 'zh', text: '简体中文', lang: 'zh-CN' },
|
||||
{ key: 'en', text: 'English', lang: 'en-US' },
|
||||
] as const;
|
||||
|
||||
function pageUrl(base: string, page: string) {
|
||||
return base + page.replace(/(^|\/)index\.md$/, '$1').replace(/\.md$/, '');
|
||||
}
|
||||
|
||||
export function useLanguageSwitcher() {
|
||||
const { page, theme, hash } = useData();
|
||||
const config = computed(() => theme.value.languageSwitcher as SwitcherConfig);
|
||||
|
||||
const current = computed(() => {
|
||||
let rest = page.value.relativePath;
|
||||
const enDir = config.value.enPrefix.replace(/^\//, '') + '/';
|
||||
const reading = rest.startsWith(enDir) ? 'en' : 'zh';
|
||||
if (reading === 'en')
|
||||
rest = rest.slice(enDir.length);
|
||||
return { reading, page: rest };
|
||||
});
|
||||
|
||||
function linkFor(reading: string, keepHash: boolean) {
|
||||
const base = reading === 'en' ? config.value.enPrefix + '/' : '/';
|
||||
const pages = config.value.pages['root'] ?? [];
|
||||
if (!pages.includes(current.value.page))
|
||||
return base;
|
||||
return pageUrl(base, current.value.page) + (keepHash ? hash.value : '');
|
||||
}
|
||||
|
||||
const isZh = computed(() => current.value.reading === 'zh');
|
||||
|
||||
const readingLanguages = computed<SwitcherLink[]>(() => READING_LANGUAGES.map(reading => ({
|
||||
text: reading.text,
|
||||
lang: reading.lang,
|
||||
link: linkFor(reading.key, true),
|
||||
active: reading.key === current.value.reading,
|
||||
})));
|
||||
|
||||
const labels = computed(() => isZh.value
|
||||
? { menu: '切换语言', reading: '阅读语言' }
|
||||
: { menu: 'Change language', reading: 'Language' });
|
||||
|
||||
const currentLabel = computed(() =>
|
||||
READING_LANGUAGES.find(reading => reading.key === current.value.reading)!.text);
|
||||
|
||||
return { readingLanguages, labels, currentLabel, isZh };
|
||||
}
|
||||
@@ -6,14 +6,16 @@ heading_anchors: false
|
||||
nav_exclude: true
|
||||
---
|
||||
|
||||
## Oops, this isn't the page you're looking for.
|
||||
## 非常遗憾,您查看的的网页没有在我们的网站上找到。
|
||||
|
||||
Maybe our [home page](https://opensearch.org/docs/latest) or one of the commonly visited pages below will help. If you need further support, please use the feedback feature on the right side of the screen to get in touch.
|
||||
可能我们的 [中文版主页](https://opensearch.isharkfly.com) 或者下面常被访问的网页能够帮助到你。
|
||||
如果想获得更多的帮助,可以单击页面右侧的反馈选项来和我们取得联系。
|
||||
|
||||
- [Quickstart]({{site.url}}{{site.baseurl}}/quickstart/)
|
||||
- [Installing OpenSearch]({{site.url}}{{site.baseurl}}/install-and-configure/install-opensearch/index/)
|
||||
- [OpenSearch Dashboards]({{site.url}}{{site.baseurl}}/dashboards/index/)
|
||||
- [Query DSL]({{site.url}}{{site.baseurl}}/query-dsl/)
|
||||
- [API Reference]({{site.url}}{{site.baseurl}}/api-reference/index/)
|
||||
- [OpenSearch 中文社区](https://www.isharkfly.com/tag/opensearch)
|
||||
- [快速开始]({{site.url}}{{site.baseurl}}/quickstart/)
|
||||
- [安装 OpenSearch]({{site.url}}{{site.baseurl}}/install-and-configure/install-opensearch/index/)
|
||||
- [OpenSearch 面板]({{site.url}}{{site.baseurl}}/dashboards/index/)
|
||||
- [查询 DSL]({{site.url}}{{site.baseurl}}/query-dsl/)
|
||||
- [API 参考]({{site.url}}{{site.baseurl}}/api-reference/index/)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
source "http://rubygems.org"
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Hello! This is where you manage which Jekyll version is used to run.
|
||||
# When you want to use a different version, change it below, save the
|
||||
|
||||
Vendored
+161
@@ -0,0 +1,161 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
disableConcurrentBuilds()
|
||||
// 文档约 1650 页(中文站点 + /en/ 英文站点各约 820 页),完整构建本地约需 8 分钟
|
||||
timeout(time: 60, unit: 'MINUTES')
|
||||
}
|
||||
|
||||
tools {
|
||||
nodejs 'NodeJS 22.14.0'
|
||||
}
|
||||
|
||||
environment {
|
||||
PRJ_NAME = 'opensearch-isharkfly-com'
|
||||
// 显式指定 wrangler 配置文件
|
||||
WRANGLER_CONFIG = 'wrangler.jsonc'
|
||||
// 本仓库原是 Jekyll 项目(根目录没有 package.json),文档工具链单独安装在 .vitepress/node_modules
|
||||
DOCS_TOOLS = '.vitepress/node_modules'
|
||||
WRANGLER = '.vitepress/node_modules/.bin/wrangler'
|
||||
// 发布到线上的分支
|
||||
RELEASE_BRANCH = 'docs_cn'
|
||||
// Cloudflare API Token(Jenkins Secret text 凭据,需要 Workers Scripts:Edit 权限)
|
||||
CLOUDFLARE_API_TOKEN = credentials('sharkdat-cloudflare-api-token')
|
||||
// Cloudflare Account ID(Secret text 凭据)。设置后 wrangler 不再调用 /memberships 查询账号,
|
||||
// 避免 token 缺少 Account 读取权限时报 "You may have incorrect permissions on your API token"
|
||||
CLOUDFLARE_ACCOUNT_ID = credentials('sharkdat-cloudflare-account-id')
|
||||
// 不让 wrangler 发送使用统计、不弹交互提示
|
||||
WRANGLER_SEND_METRICS = 'false'
|
||||
CI = 'true'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Configure') {
|
||||
steps {
|
||||
sh 'git config --global url."https://github.com/".insteadOf git://github.com/'
|
||||
sh '''
|
||||
set -eu
|
||||
node --version
|
||||
npm --version
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install') {
|
||||
steps {
|
||||
// 只安装文档工具链(VitePress + Wrangler),不需要 Ruby / Jekyll
|
||||
sh '''
|
||||
set -eu
|
||||
npm install --prefix .vitepress --no-save --no-package-lock --no-audit --no-fund \
|
||||
[email protected] [email protected] [email protected]
|
||||
# VitePress 只在客户端构建时把 vue 指向自带依赖;SSR 构建时 site/ 下的页面按 Node 规则
|
||||
# 向上查找 node_modules/vue。让根目录 node_modules 指向工具链,保证只有一份 vue。
|
||||
ln -sfn .vitepress/node_modules node_modules
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Build VitePress docs ...'
|
||||
sh '''
|
||||
set -eu
|
||||
node scripts/generate.mjs
|
||||
node scripts/sync-zh.mjs
|
||||
# 默认堆内存(及 8 GB)构建时会内存溢出,需 16 GB
|
||||
node --max-old-space-size=16384 ${DOCS_TOOLS}/vitepress/bin/vitepress.js build .
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy - CF') {
|
||||
steps {
|
||||
script {
|
||||
withEnv([
|
||||
'LANG=C.UTF-8',
|
||||
'LC_ALL=C.UTF-8',
|
||||
'NO_COLOR=1',
|
||||
'TERM=dumb'
|
||||
]) {
|
||||
// 部署消息:显示在 Cloudflare 控制台 → Worker → Deployments
|
||||
def shortSha = env.GIT_COMMIT ? env.GIT_COMMIT.take(7) : 'unknown'
|
||||
def deployMsg = "Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER} (${shortSha})"
|
||||
|
||||
// Tag 构建:部署到 production 环境(wrangler.jsonc 中的 env.production)
|
||||
if (env.TAG_NAME?.trim()) {
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env production \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${env.TAG_NAME}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// main 分支:部署默认 Worker
|
||||
if (env.BRANCH_NAME == env.RELEASE_BRANCH) {
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${shortSha}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// PR 或其他分支:上传 Preview Version,不影响线上流量
|
||||
def branchArg = env.CHANGE_ID
|
||||
? "pr-${env.CHANGE_ID}"
|
||||
: env.BRANCH_NAME
|
||||
|
||||
def previewAlias = branchArg
|
||||
.toLowerCase()
|
||||
.replaceAll(/[^a-z0-9-]+/, '-')
|
||||
.replaceAll(/^-+|-+$/, '')
|
||||
|
||||
// 打印当前 token 所属账号,便于排查 "Worker does not yet exist"(通常是账号不对)
|
||||
sh "${env.WRANGLER} whoami"
|
||||
|
||||
// versions upload 要求 Worker 已存在;首次构建时先 deploy 一次创建 Worker
|
||||
def workerExists = sh(
|
||||
script: "${env.WRANGLER} deployments list --config ${env.WRANGLER_CONFIG} --env=\"\" > /dev/null 2>&1",
|
||||
returnStatus: true
|
||||
) == 0
|
||||
if (!workerExists) {
|
||||
echo "Worker ${env.PRJ_NAME} 尚不存在,先执行首次 deploy 创建 Worker ..."
|
||||
sh """
|
||||
${env.WRANGLER} deploy --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--message 'Initial deploy: ${deployMsg}'
|
||||
"""
|
||||
}
|
||||
|
||||
sh """
|
||||
${env.WRANGLER} versions upload --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--preview-alias '${previewAlias}' \
|
||||
--message 'Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
env.BUILD_STARTED_AT = new Date(currentBuild.startTimeInMillis)
|
||||
.format('yyyy-MM-dd HH:mm:ss z', TimeZone.getTimeZone('America/New_York'))
|
||||
|
||||
env.BUILD_DURATION_TEXT = currentBuild.durationString
|
||||
|
||||
emailext (
|
||||
mimeType: 'text/html; charset=UTF-8',
|
||||
subject: "Build ${currentBuild.currentResult}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
||||
body: '${DEFAULT_CONTENT}',
|
||||
from: '[email protected]',
|
||||
to: '[email protected], [email protected]'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
title: OpenSearch Documentation
|
||||
description: >- # this means to ignore newlines until "baseurl:"
|
||||
Documentation for OpenSearch, the Apache 2.0 search, analytics, and visualization suite with advanced security, alerting, SQL support, automated index management, deep performance analysis, and more.
|
||||
baseurl: "/docs/latest" # the subpath of your site, e.g. /blog
|
||||
url: "https://opensearch.org" # the base hostname & protocol for your site, e.g. http://example.com
|
||||
baseurl: "" # the subpath of your site, e.g. /blog
|
||||
url: "https://opensearch.isharkfly.com" # the base hostname & protocol for your site, e.g. http://example.com
|
||||
permalink: /:path/
|
||||
|
||||
opensearch_version: '2.12.0'
|
||||
@@ -280,7 +280,7 @@ search:
|
||||
|
||||
# Google Analytics Tracking (optional)
|
||||
# e.g, UA-1234567-89
|
||||
ga_tracking: G-BQV14XK08F
|
||||
ga_tracking: GTM-W3NL9V
|
||||
|
||||
# Disable the just-the-docs theme anchor links in favor of our custom ones
|
||||
# See _includes/head_custom.html
|
||||
|
||||
+21
-12
@@ -1,29 +1,38 @@
|
||||
columns:
|
||||
-
|
||||
title: 'Get Involved'
|
||||
title: '参与项目(Get Involved)'
|
||||
links:
|
||||
-
|
||||
title: Code of Conduct
|
||||
url: '/codeofconduct.html'
|
||||
-
|
||||
title: 'Forum'
|
||||
url: 'https://forum.opensearch.org/'
|
||||
title: 'OpenSearch 中文论坛'
|
||||
url: 'https://www.isharkfly.com/tag/opensearch'
|
||||
-
|
||||
title: 'Github'
|
||||
title: '官方论坛'
|
||||
url: 'https://discuss.opendistrocommunity.dev/'
|
||||
-
|
||||
title: '中文文档代码仓库'
|
||||
url: 'https://github.com/iSharkFly-Docs/opensearch-docs-cn'
|
||||
-
|
||||
title: '官方 Github'
|
||||
url: 'https://github.com/opensearch-project'
|
||||
-
|
||||
title: 'Slack'
|
||||
url: '/slack.html'
|
||||
url: 'https://opensearch.org/slack.html'
|
||||
-
|
||||
title: '社区项目'
|
||||
url: '/community_projects'
|
||||
-
|
||||
title: 'Resources'
|
||||
title: '资源(Resources)'
|
||||
links:
|
||||
-
|
||||
-
|
||||
title: About
|
||||
url: '/about.html'
|
||||
-
|
||||
-
|
||||
title: Release Schedule
|
||||
url: '/releases.html'
|
||||
-
|
||||
-
|
||||
title: Maintenance Policy
|
||||
url: '/releases.html#maintenance-policy'
|
||||
-
|
||||
@@ -39,11 +48,11 @@ columns:
|
||||
title: 'Privacy'
|
||||
url: 'https://aws.amazon.com/privacy/'
|
||||
-
|
||||
title: 'Contact Us'
|
||||
title: '联系我们(Contact Us)'
|
||||
links:
|
||||
-
|
||||
title: 'Connect'
|
||||
url: '/connect.html'
|
||||
title: '联系(Connect)'
|
||||
url: 'https://www.isharkfly.com/t/opensearch/15530'
|
||||
-
|
||||
title: 'Twitter'
|
||||
url: 'https://twitter.com/OpenSearchProj'
|
||||
|
||||
Executable
+1
-1
@@ -1 +1 @@
|
||||
opensearch.ossez.com
|
||||
opensearch.isharkfly.com
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"database": {
|
||||
"rules": "database.rules.json"
|
||||
},
|
||||
"hosting": {
|
||||
"public": "_site",
|
||||
"ignore": [
|
||||
"firebase.json",
|
||||
"**/.*",
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# OpenSearch 文档中文翻译规范
|
||||
|
||||
## 文件位置
|
||||
|
||||
- Jekyll 原文:`_<collection>/<路径>.md`(例如 `_query-dsl/full-text/match.md`),跟随官方仓库更新,**不要修改**。
|
||||
- 英文原文(VitePress 版):`src/<路径>.md`,由 `node scripts/import-jekyll.mjs` 从 Jekyll 原文转换生成,**不要手工修改**(`src/index.md` 首页除外)。构建时 `scripts/sync-zh.mjs` 会把它发布到 `/en/<路径>`。
|
||||
- 中文译文:`i18n/zh/<路径>.md`,与 `src/` 下的路径一一对应。构建时发布到站点根路径 `/<路径>`。
|
||||
- **翻译时以 `src/` 下的文件为原文**,不要以 `_<collection>/` 下的 Jekyll 文件为原文:`src/` 中已经把 Liquid 变量、`{: .note}` 等 kramdown 语法转换成了 VitePress 语法。
|
||||
- 没有译文的页面会自动以英文显示并标记 `untranslated: true`。
|
||||
|
||||
## 翻译要求
|
||||
|
||||
1. 读者是中文开发者和运维人员。译文要自然、通顺,不要逐词硬译;使用简体中文。
|
||||
2. **术语**:OpenSearch 核心术语首次出现时写成「中文(English)」,之后只用中文。例如:索引(Index)、文档(Document)、字段(Field)、映射(Mapping)、分片(Shard)、主分片(Primary Shard)、副本分片(Replica Shard)、节点(Node)、集群(Cluster)、集群管理节点(Cluster Manager Node)、分析器(Analyzer)、分词器(Tokenizer)、词元过滤器(Token Filter)、聚合(Aggregation)、桶聚合(Bucket Aggregation)、指标聚合(Metric Aggregation)、查询(Query)、过滤器(Filter)、相关性评分(Relevance Score)、摄取管道(Ingest Pipeline)、处理器(Processor)、搜索管道(Search Pipeline)、快照(Snapshot)、别名(Alias)、索引模板(Index Template)、索引状态管理(Index State Management,ISM)、段(Segment)、段复制(Segment Replication)、远程存储(Remote Store)、跨集群复制(Cross-cluster Replication)、可观测性(Observability)、向量搜索(Vector Search)、神经搜索(Neural Search)、混合搜索(Hybrid Search)。
|
||||
其他已统一的译法:插件(plugin)、仪表板(dashboard,产品名 OpenSearch Dashboards 不译)、可视化(visualization)、告警(alerting)、监控器(monitor)、角色(role)、权限(permission)、租户(tenant)。
|
||||
3. 产品名、库名、API 名称和代码标识符保持英文:OpenSearch、OpenSearch Dashboards、Data Prepper、OpenSearch Benchmark、Lucene、Query DSL、PPL、SQL、k-NN、`_search`、`match`、`bool` 等。API 的端点、参数名和字段名保持英文。
|
||||
4. **不翻译**:代码块内的代码、行内代码(反引号内)、文件路径、命令、URL、HTML 标签和属性、Vue/VitePress 组件标签及属性名(例如 `<Badge type="tip" text="Introduced 1.0" />` 中的 `text` 值保留英文)。代码块中的**注释**可以翻译。
|
||||
- 代码块的整行 fence(包括 ```` ```json ```` 这类语言标记)保持原样,不要翻译。
|
||||
- 示例请求和示例响应(JSON、YAML、curl 命令)保持原样。
|
||||
5. **保持结构**:标题层级、列表、表格、`:::` 容器、HTML 片段、空行和 frontmatter 的键名都保持原样。frontmatter 中的 `title`、`description` 等文字值要翻译。
|
||||
- 容器标题统一译为:NOTE → 注意,TIP → 提示,IMPORTANT → 重要,WARNING → 警告。例如 `::: info NOTE` 译为 `::: info 注意`。
|
||||
- API 参数表格:参数名、数据类型(Boolean、String、Integer 等)保持英文,只翻译描述列。
|
||||
6. **链接**:链接地址保持原样(站内的 `/xxx` 链接会自动指向中文页面),只翻译链接文字。锚点链接(`#some-heading`)保持原样。
|
||||
- 标题锚点不用手动处理:`scripts/sync-zh.mjs` 构建时会按顺序把中文标题与英文标题配对,自动加上英文锚点 `{#english-slug}`。因此**译文的标题数量和顺序必须与原文完全一致**,不能合并、拆分或增删标题。原文已有的 `{#xxx}` 保持原样。
|
||||
7. 中英文之间、中文与数字之间加一个空格。中文语境下使用全角标点(,。:;?!「」()),代码和英文内容中保持半角。
|
||||
8. 不要增删内容,不要添加译者注,除非原文有明显错误。
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: OpenSearch
|
||||
text: 中文文档
|
||||
tagline: 学习使用 OpenSearch —— 一套高度可扩展、可定制的开源软件,适用于搜索、分析、可观测性以及其他数据密集型应用。
|
||||
image:
|
||||
src: /favicon.svg
|
||||
alt: OpenSearch
|
||||
actions:
|
||||
- theme: brand
|
||||
text: 开始使用
|
||||
link: /about/
|
||||
- theme: alt
|
||||
text: 快速入门
|
||||
link: /quickstart
|
||||
- theme: alt
|
||||
text: API 参考
|
||||
link: /api-reference/
|
||||
|
||||
features:
|
||||
- title: OpenSearch 与 OpenSearch Dashboards
|
||||
details: 使用核心工具和可视化功能构建你的 OpenSearch 解决方案。
|
||||
link: /about/
|
||||
linkText: 查看文档
|
||||
- title: Data Prepper
|
||||
details: 在数据摄取到 OpenSearch 之前进行过滤、转换和采样。
|
||||
link: /data-prepper/
|
||||
linkText: 查看文档
|
||||
- title: 客户端(Clients)
|
||||
details: 在你的应用程序中通过各语言的 API 与 OpenSearch 交互。
|
||||
link: /clients/
|
||||
linkText: 查看文档
|
||||
- title: OpenSearch Benchmark
|
||||
details: 度量 OpenSearch 集群的性能指标。
|
||||
link: /benchmark/
|
||||
linkText: 查看文档
|
||||
---
|
||||
@@ -0,0 +1,50 @@
|
||||
// Generates the site.json configuration file for the OpenSearch documentation.
|
||||
// The sidebar comes from scripts/nav.json, which import-jekyll.mjs writes from the
|
||||
// just-the-docs front matter (title / parent / grand_parent / nav_order).
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const SITE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const NAV_FILE = path.join(SITE_DIR, 'scripts', 'nav.json');
|
||||
const GENERATED_DIR = path.join(SITE_DIR, '.vitepress', 'generated');
|
||||
|
||||
function toSidebarItems(items) {
|
||||
return items.map(item => {
|
||||
if (item.items)
|
||||
return { text: item.text, link: item.link, collapsed: true, items: toSidebarItems(item.items) };
|
||||
return { text: item.text, link: item.link };
|
||||
});
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (!fs.existsSync(NAV_FILE))
|
||||
throw new Error('scripts/nav.json is missing. Run "node scripts/import-jekyll.mjs" first.');
|
||||
const nav = JSON.parse(fs.readFileSync(NAV_FILE, 'utf8'));
|
||||
|
||||
// One sidebar per just-the-docs section: OpenSearch (/), Clients, Benchmark, Data Prepper.
|
||||
const sidebar = {};
|
||||
for (const section of nav) {
|
||||
sidebar[section.base] = section.groups.map(group => ({
|
||||
text: group.text,
|
||||
collapsed: section.groups.length > 1,
|
||||
items: toSidebarItems(group.items),
|
||||
}));
|
||||
}
|
||||
|
||||
fs.mkdirSync(GENERATED_DIR, { recursive: true });
|
||||
const site = {
|
||||
locales: {
|
||||
root: {
|
||||
label: 'OpenSearch',
|
||||
base: '/',
|
||||
sidebar,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
fs.writeFileSync(path.join(GENERATED_DIR, 'site.json'), JSON.stringify(site, null, 2));
|
||||
console.log('[generate] Generated site.json');
|
||||
}
|
||||
|
||||
main();
|
||||
File diff suppressed because it is too large
Load Diff
+3574
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
// Assembles the bilingual site in site/ (generated, git-ignored) from src/ (English)
|
||||
// and i18n/zh/ (Chinese translations).
|
||||
// Simplified Chinese is served from the site root; English from /en/.
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const SITE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const SRC_DIR = path.join(SITE_DIR, 'src');
|
||||
const OUT_DIR = path.join(SITE_DIR, 'site');
|
||||
const EN_DIR = 'en';
|
||||
const ZH_TRANSLATIONS_DIR = path.join(SITE_DIR, 'i18n', 'zh');
|
||||
|
||||
const SKIP_DIRS = new Set(['public', 'zh', EN_DIR]);
|
||||
// Static files kept at the repository root (shared with the Jekyll sources) and
|
||||
// served from the site root. Cloudflare Workers Static Assets rejects files > 25 MiB.
|
||||
const STATIC_DIRS = ['images', 'assets'];
|
||||
const MAX_ASSET_BYTES = 25 * 1024 * 1024;
|
||||
const STATIC_PREFIXES = ['images/', 'img/', 'assets/', `${EN_DIR}/`];
|
||||
|
||||
function listMarkdown(dir, rel = '') {
|
||||
const files = [];
|
||||
if (!fs.existsSync(dir))
|
||||
return files;
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const entryRel = rel ? `${rel}/${entry.name}` : entry.name;
|
||||
if (entry.isDirectory()) {
|
||||
if (!rel && SKIP_DIRS.has(entry.name))
|
||||
continue;
|
||||
files.push(...listMarkdown(path.join(dir, entry.name), entryRel));
|
||||
} else if (entry.name.endsWith('.md')) {
|
||||
files.push(entryRel);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
function toEnglishPath(target) {
|
||||
return STATIC_PREFIXES.some(prefix => target.startsWith(prefix)) ? `/${target}` : `/${EN_DIR}/${target}`;
|
||||
}
|
||||
|
||||
function moveLinksUnderEnglish(text) {
|
||||
return text
|
||||
.replace(/\]\(\/(?!\/)([^)\s]*)/g, (_, target) => `](${toEnglishPath(target)}`)
|
||||
.replace(/\bhref="\/(?!\/)([^"]*)"/g, (_, target) => `href="${toEnglishPath(target)}"`)
|
||||
.replace(/^(\s*link:\s*)\/(?!\/)(\S*)/gm, (_, prefix, target) => `${prefix}${toEnglishPath(target)}`);
|
||||
}
|
||||
|
||||
function markUntranslated(text) {
|
||||
if (text.startsWith('---\n') || text.startsWith('---\r\n'))
|
||||
return text.replace(/^---\r?\n/, '---\nuntranslated: true\n');
|
||||
return `---\nuntranslated: true\n---\n\n${text}`;
|
||||
}
|
||||
|
||||
// Same algorithm as VitePress's default heading slugify.
|
||||
function slugify(str) {
|
||||
return str.normalize('NFKD')
|
||||
.replace(/[̀-ͯ]/g, '')
|
||||
.replace(/[\u0000-\u001f]/g, '')
|
||||
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g, '-')
|
||||
.replace(/-{2,}/g, '-')
|
||||
.replace(/^-+|-+$/g, '')
|
||||
.replace(/^(\d)/, '_$1')
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
const HEADING = /^(#{1,6})\s+(.*?)\s*$/;
|
||||
const CUSTOM_ID = /\s*\{#([^}]+)\}\s*$/;
|
||||
|
||||
// Line indexes of ATX headings outside fenced code blocks and frontmatter.
|
||||
function headingLines(lines) {
|
||||
const result = [];
|
||||
let fence = null;
|
||||
let i = 0;
|
||||
if (lines[0]?.trim() === '---') {
|
||||
i = lines.findIndex((line, idx) => idx > 0 && line.trim() === '---') + 1;
|
||||
}
|
||||
for (; i < lines.length; i++) {
|
||||
const fenceMatch = lines[i].match(/^\s*(`{3,}|~{3,})/);
|
||||
if (fenceMatch) {
|
||||
if (!fence) fence = fenceMatch[1];
|
||||
else if (lines[i].trim().startsWith(fence)) fence = null;
|
||||
continue;
|
||||
}
|
||||
if (!fence && HEADING.test(lines[i])) result.push(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Plain text of a heading as rendered, which is what VitePress slugifies.
|
||||
function headingText(raw) {
|
||||
return raw
|
||||
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1')
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/`([^`]*)`/g, '$1')
|
||||
.replace(/(\*\*|__|\*|_)(?=\S)([^*_]*?\S)\1/g, '$2')
|
||||
.trim();
|
||||
}
|
||||
|
||||
// Give each translated heading the English heading's id, so that #anchor links
|
||||
// written against the English text keep working on the Chinese page.
|
||||
function keepEnglishAnchors(rel, english, chinese) {
|
||||
const enLines = english.split(/\r?\n/);
|
||||
const zhLines = chinese.split(/\r?\n/);
|
||||
const enHeadings = headingLines(enLines);
|
||||
const zhHeadings = headingLines(zhLines);
|
||||
if (enHeadings.length !== zhHeadings.length) {
|
||||
console.warn(`[sync-zh] i18n/zh/${rel}: ${zhHeadings.length} headings vs ${enHeadings.length} in English; anchors not aligned.`);
|
||||
return chinese;
|
||||
}
|
||||
const seen = new Map();
|
||||
enHeadings.forEach((enIdx, n) => {
|
||||
const [, , enRaw] = enLines[enIdx].match(HEADING);
|
||||
const custom = enRaw.match(CUSTOM_ID);
|
||||
let id = custom ? custom[1] : slugify(headingText(enRaw));
|
||||
if (!custom) {
|
||||
const count = seen.get(id) ?? 0;
|
||||
seen.set(id, count + 1);
|
||||
if (count) id = `${id}-${count}`;
|
||||
}
|
||||
const zhIdx = zhHeadings[n];
|
||||
if (!CUSTOM_ID.test(zhLines[zhIdx]) && id)
|
||||
zhLines[zhIdx] = `${zhLines[zhIdx].trimEnd()} {#${id}}`;
|
||||
});
|
||||
return zhLines.join('\n');
|
||||
}
|
||||
|
||||
function write(rel, text) {
|
||||
const file = path.join(OUT_DIR, rel);
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, text);
|
||||
}
|
||||
|
||||
function copyStatic() {
|
||||
for (const dir of STATIC_DIRS) {
|
||||
const from = path.join(SITE_DIR, dir);
|
||||
if (!fs.existsSync(from))
|
||||
continue;
|
||||
fs.cpSync(from, path.join(OUT_DIR, 'public', dir), {
|
||||
recursive: true,
|
||||
filter: file => {
|
||||
const stat = fs.statSync(file);
|
||||
if (stat.isFile() && stat.size > MAX_ASSET_BYTES) {
|
||||
console.warn(`[sync-zh] ${path.relative(SITE_DIR, file)} is larger than 25 MiB and was not copied.`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
fs.rmSync(OUT_DIR, { recursive: true, force: true });
|
||||
fs.mkdirSync(OUT_DIR, { recursive: true });
|
||||
if (fs.existsSync(path.join(SRC_DIR, 'public')))
|
||||
fs.cpSync(path.join(SRC_DIR, 'public'), path.join(OUT_DIR, 'public'), { recursive: true });
|
||||
copyStatic();
|
||||
|
||||
let translated = 0;
|
||||
const pages = listMarkdown(SRC_DIR);
|
||||
for (const rel of pages) {
|
||||
const english = fs.readFileSync(path.join(SRC_DIR, rel), 'utf8');
|
||||
write(`${EN_DIR}/${rel}`, moveLinksUnderEnglish(english));
|
||||
|
||||
const translationFile = path.join(ZH_TRANSLATIONS_DIR, rel);
|
||||
if (fs.existsSync(translationFile)) {
|
||||
write(rel, keepEnglishAnchors(rel, english, fs.readFileSync(translationFile, 'utf8')));
|
||||
translated++;
|
||||
} else {
|
||||
write(rel, markUntranslated(english));
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(ZH_TRANSLATIONS_DIR)) {
|
||||
const known = new Set(pages);
|
||||
for (const rel of listMarkdown(ZH_TRANSLATIONS_DIR)) {
|
||||
if (!known.has(rel))
|
||||
console.warn(`[sync-zh] i18n/zh/${rel} has no English page in src/ and was skipped.`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[sync-zh] ${pages.length} pages: Chinese in site/ (${translated} translated), English in site/${EN_DIR}/.`);
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: Getting started
|
||||
---
|
||||
|
||||
# OpenSearch and OpenSearch Dashboards
|
||||
<Badge type="tip" text="Version 2.12" />
|
||||
|
||||
This section contains documentation for OpenSearch and OpenSearch Dashboards.
|
||||
|
||||
## Getting started
|
||||
|
||||
- [Intro to OpenSearch](/intro)
|
||||
- [Quickstart](/quickstart)
|
||||
- [Install OpenSearch](/install-and-configure/install-opensearch/)
|
||||
- [Install OpenSearch Dashboards](/install-and-configure/install-dashboards/)
|
||||
- [See the FAQ](https://opensearch.org/faq)
|
||||
|
||||
## Why use OpenSearch?
|
||||
|
||||
With OpenSearch, you can perform the following use cases:
|
||||
|
||||
<table style="table-layout: auto ; width: 100%;">
|
||||
<tbody>
|
||||
<tr style="text-align: center; vertical-align:center;">
|
||||
<td><img src="/images/1_search.png" class="no-border" alt="Fast, scalable full-text search" height="100"/></td>
|
||||
<td><img src="/images/2_monitoring.png" class="no-border" alt="Application and infrastructure monitoring" height="100"/></td>
|
||||
<td><img src="/images/3_security.png" class="no-border" alt="Security and event information management" height="100"/></td>
|
||||
<td><img src="/images/4_tracking.png" class="no-border" alt="Operational health tracking" height="100"/></td>
|
||||
</tr>
|
||||
<tr style="text-align: left; vertical-align:top; font-weight: bold; color: rgb(0,59,92)">
|
||||
<td>Fast, Scalable Full-text Search</td>
|
||||
<td>Application and Infrastructure Monitoring</td>
|
||||
<td>Security and Event Information Management</td>
|
||||
<td>Operational Health Tracking</td>
|
||||
</tr>
|
||||
<tr style="text-align: left; vertical-align:top;">
|
||||
<td>Help users find the right information within your application, website, or data lake catalog. </td>
|
||||
<td>Easily store and analyze log data, and set automated alerts for underperformance.</td>
|
||||
<td>Centralize logs to enable real-time security monitoring and forensic analysis.</td>
|
||||
<td>Use observability logs, metrics, and traces to monitor your applications and business in real time.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Additional features and plugins:**
|
||||
|
||||
OpenSearch has several features and plugins to help index, secure, monitor, and analyze your data. Most OpenSearch plugins have corresponding OpenSearch Dashboards plugins that provide a convenient, unified user interface.
|
||||
- [Anomaly detection](/observing-your-data/ad/) - Identify atypical data and receive automatic notifications
|
||||
- [KNN](/search-plugins/knn/) - Find “nearest neighbors” in your vector data
|
||||
- [Performance Analyzer](/monitoring-your-cluster/pa/) - Monitor and optimize your cluster
|
||||
- [SQL](/search-plugins/sql/) - Use SQL or a piped processing language to query your data
|
||||
- [Index State Management](/im-plugin/) - Automate index operations
|
||||
- [ML Commons plugin](/ml-commons-plugin/) - Train and execute machine-learning models
|
||||
- [Asynchronous search](/search-plugins/async/) - Run search requests in the background
|
||||
- [Cross-cluster replication](/tuning-your-cluster/replication-plugin/) - Replicate your data across multiple OpenSearch clusters
|
||||
|
||||
## The secure path forward
|
||||
OpenSearch includes a demo configuration so that you can get up and running quickly, but before using OpenSearch in a production environment, you must [configure the Security plugin manually](/security/configuration/) with your own certificates, authentication method, users, and passwords.
|
||||
|
||||
## Looking for the Javadoc?
|
||||
|
||||
See [opensearch.org/javadocs/](https://opensearch.org/javadocs/).
|
||||
|
||||
## Get involved
|
||||
|
||||
[OpenSearch](https://opensearch.org) is supported by Amazon Web Services. All components are available under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) on [GitHub](https://github.com/opensearch-project/).
|
||||
The project welcomes GitHub issues, bug fixes, features, plugins, documentation---anything at all. To get involved, see [Contributing](https://opensearch.org/source.html) on the OpenSearch website.
|
||||
|
||||
---
|
||||
|
||||
<small>OpenSearch includes certain Apache-licensed Elasticsearch code from Elasticsearch B.V. and other source code. Elasticsearch B.V. is not the source of that other source code. ELASTICSEARCH is a registered trademark of Elasticsearch B.V.</small>
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
title: Adjacency matrix
|
||||
---
|
||||
|
||||
# Adjacency matrix aggregations
|
||||
|
||||
The `adjacency_matrix` aggregation lets you define filter expressions and returns a matrix of the intersecting filters where each non-empty cell in the matrix represents a bucket. You can find how many documents fall within any combination of filters.
|
||||
|
||||
Use the `adjacency_matrix` aggregation to discover how concepts are related by visualizing the data as graphs.
|
||||
|
||||
For example, in the sample eCommerce dataset, to analyze how the different manufacturing companies are related:
|
||||
|
||||
```json
|
||||
GET opensearch_dashboards_sample_data_ecommerce/_search
|
||||
{
|
||||
"size": 0,
|
||||
"aggs": {
|
||||
"interactions": {
|
||||
"adjacency_matrix": {
|
||||
"filters": {
|
||||
"grpA": {
|
||||
"match": {
|
||||
"manufacturer.keyword": "Low Tide Media"
|
||||
}
|
||||
},
|
||||
"grpB": {
|
||||
"match": {
|
||||
"manufacturer.keyword": "Elitelligence"
|
||||
}
|
||||
},
|
||||
"grpC": {
|
||||
"match": {
|
||||
"manufacturer.keyword": "Oceanavigations"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example response
|
||||
|
||||
```json
|
||||
{
|
||||
...
|
||||
"aggregations" : {
|
||||
"interactions" : {
|
||||
"buckets" : [
|
||||
{
|
||||
"key" : "grpA",
|
||||
"doc_count" : 1553
|
||||
},
|
||||
{
|
||||
"key" : "grpA&grpB",
|
||||
"doc_count" : 590
|
||||
},
|
||||
{
|
||||
"key" : "grpA&grpC",
|
||||
"doc_count" : 329
|
||||
},
|
||||
{
|
||||
"key" : "grpB",
|
||||
"doc_count" : 1370
|
||||
},
|
||||
{
|
||||
"key" : "grpB&grpC",
|
||||
"doc_count" : 299
|
||||
},
|
||||
{
|
||||
"key" : "grpC",
|
||||
"doc_count" : 1218
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Let’s take a closer look at the result:
|
||||
|
||||
```json
|
||||
{
|
||||
"key" : "grpA&grpB",
|
||||
"doc_count" : 590
|
||||
}
|
||||
```
|
||||
|
||||
- `grpA`: Products manufactured by Low Tide Media.
|
||||
- `grpB`: Products manufactured by Elitelligence.
|
||||
- `590`: Number of products that are manufactured by both.
|
||||
|
||||
You can use OpenSearch Dashboards to represent this data with a network graph.
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
title: Date histogram
|
||||
---
|
||||
|
||||
# Date histogram aggregations
|
||||
|
||||
The `date_histogram` aggregation uses [date math](/field-types/supported-field-types/date#date-math) to generate histograms for time-series data.
|
||||
|
||||
For example, you can find how many hits your website gets per month:
|
||||
|
||||
```json
|
||||
GET opensearch_dashboards_sample_data_logs/_search
|
||||
{
|
||||
"size": 0,
|
||||
"aggs": {
|
||||
"logs_per_month": {
|
||||
"date_histogram": {
|
||||
"field": "@timestamp",
|
||||
"interval": "month"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example response
|
||||
|
||||
```json
|
||||
...
|
||||
"aggregations" : {
|
||||
"logs_per_month" : {
|
||||
"buckets" : [
|
||||
{
|
||||
"key_as_string" : "2020-10-01T00:00:00.000Z",
|
||||
"key" : 1601510400000,
|
||||
"doc_count" : 1635
|
||||
},
|
||||
{
|
||||
"key_as_string" : "2020-11-01T00:00:00.000Z",
|
||||
"key" : 1604188800000,
|
||||
"doc_count" : 6844
|
||||
},
|
||||
{
|
||||
"key_as_string" : "2020-12-01T00:00:00.000Z",
|
||||
"key" : 1606780800000,
|
||||
"doc_count" : 5595
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The response has three months worth of logs. If you graph these values, you can see the peak and valleys of the request traffic to your website month over month.
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: Date range
|
||||
---
|
||||
|
||||
# Date range aggregations
|
||||
|
||||
The `date_range` aggregation is conceptually the same as the `range` aggregation, except that it lets you perform date math.
|
||||
For example, you can get all documents from the last 10 days. To make the date more readable, include the format with a `format` parameter:
|
||||
|
||||
```json
|
||||
GET opensearch_dashboards_sample_data_logs/_search
|
||||
{
|
||||
"size": 0,
|
||||
"aggs": {
|
||||
"number_of_bytes": {
|
||||
"date_range": {
|
||||
"field": "@timestamp",
|
||||
"format": "MM-yyyy",
|
||||
"ranges": [
|
||||
{
|
||||
"from": "now-10d/d",
|
||||
"to": "now"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example response
|
||||
|
||||
```json
|
||||
...
|
||||
"aggregations" : {
|
||||
"number_of_bytes" : {
|
||||
"buckets" : [
|
||||
{
|
||||
"key" : "03-2021-03-2021",
|
||||
"from" : 1.6145568E12,
|
||||
"from_as_string" : "03-2021",
|
||||
"to" : 1.615451329043E12,
|
||||
"to_as_string" : "03-2021",
|
||||
"doc_count" : 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: Diversified sampler
|
||||
---
|
||||
|
||||
# Diversified sampler
|
||||
|
||||
The `diversified_sampler` aggregation lets you reduce the bias in the distribution of the sample pool by deduplicating documents containing the same `field`. It does so by using the `max_docs_per_value` and `field` settings, which limit the maximum number of documents collected on a shard for the provided `field`. The `max_docs_per_value` setting is an optional parameter used to determine the maximum number of documents that will be returned per `field`. The default value of this setting is `1`.
|
||||
|
||||
Similarly to the [`sampler` aggregation](/aggregations/bucket/sampler), you can use the `shard_size` setting to control the maximum number of documents collected on any one shard, as shown in the following example:
|
||||
|
||||
```json
|
||||
GET opensearch_dashboards_sample_data_logs/_search
|
||||
{
|
||||
"size": 0,
|
||||
"aggs": {
|
||||
"sample": {
|
||||
"diversified_": {
|
||||
"shard_size": 1000,
|
||||
"field": "response.keyword"
|
||||
},
|
||||
"aggs": {
|
||||
"terms": {
|
||||
"terms": {
|
||||
"field": "agent.keyword"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example response
|
||||
|
||||
```json
|
||||
...
|
||||
"aggregations" : {
|
||||
"sample" : {
|
||||
"doc_count" : 3,
|
||||
"terms" : {
|
||||
"doc_count_error_upper_bound" : 0,
|
||||
"sum_other_doc_count" : 0,
|
||||
"buckets" : [
|
||||
{
|
||||
"key" : "Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1",
|
||||
"doc_count" : 2
|
||||
},
|
||||
{
|
||||
"key" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
|
||||
"doc_count" : 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
title: Filter
|
||||
---
|
||||
|
||||
# Filter aggregations
|
||||
|
||||
A `filter` aggregation is a query clause, exactly like a search query — `match` or `term` or `range`. You can use the `filter` aggregation to narrow down the entire set of documents to a specific set before creating buckets.
|
||||
|
||||
The following example shows the `avg` aggregation running within the context of a filter. The `avg` aggregation only aggregates the documents that match the `range` query:
|
||||
|
||||
```json
|
||||
GET opensearch_dashboards_sample_data_ecommerce/_search
|
||||
{
|
||||
"size": 0,
|
||||
"aggs": {
|
||||
"low_value": {
|
||||
"filter": {
|
||||
"range": {
|
||||
"taxful_total_price": {
|
||||
"lte": 50
|
||||
}
|
||||
}
|
||||
},
|
||||
"aggs": {
|
||||
"avg_amount": {
|
||||
"avg": {
|
||||
"field": "taxful_total_price"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Example response
|
||||
|
||||
```json
|
||||
...
|
||||
"aggregations" : {
|
||||
"low_value" : {
|
||||
"doc_count" : 1633,
|
||||
"avg_amount" : {
|
||||
"value" : 38.363175998928355
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user