@10up/elasticpress-react 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

ElasticPress React

ElasticPress React 是一个 React 组件库,可使用 ElasticPress 增强您的无头 WordPress 网站。

支持级别“发布版本”GPLv2 License

Requirements

Installation

要安装 ElasticPress React,只需通过 npm 安装:

npm install @10up/elasticpress-react --save

您将需要一个 Elasticsearch 实例和一个运行 ElasticPress

Components

ElasticPressProvider

您必须使用 ElasticPressProvider 包装您的应用程序才能使用 ElasticPress 组件。

    <ElasticPressProvider
        node="http://elasticpress.test/__elasticsearch"
        indexName="elasticpresstest-post-1"
    >
        {/* ElasticPress Components */}
    </ElasticPressProvider>

Autosuggest

该组件输出一个搜索字段,在输入时会自动向用户建议结果。

import { AutosuggestField } from '@10up/elasticpress-react';

const MyComponent = () => (
    <>
        <p>Here is my fancy new component.</p>

        <p>Here's a search input with autosuggest:</p>

        <ElasticPressProvider
                node="http://elasticpress.test/__elasticsearch"
                indexName="elasticpresstest-post-1"
                loadInitialData={false}
            >
                <AutosuggestField />
            </ElasticPressProvider>
    </>
);

Screenshot

Autosuggest screenshot

Related Content

该组件输出与帖子相关的内容。

import { RelatedContent } from '@10up/elasticpress-react';

const MyComponent = () => (
    <>
        <p>Here is my fancy new component.</p>

        <p>Here is some related content to post 5:</p>

        <RelatedContent
            wpApiRoot="https://mysite.com/wp-json"
            postId="5"
        />
    </>
);

Search and Post Results

import { PostContextProvider, SearchField, Posts } from '@10up/elasticpress-react';

const MyComponent = () => {
    // Make sure to wrap your components with the provider.
    return (
        <ElasticPressProvider
            node="http://elasticpress.test/__elasticsearch"
            indexName="elasticpresstest-post-1"
        >
            <div>
                <SearchField />
            </div>

            <div>
                <Posts />
            </div>
        </ElasticPressProvider>
    );
};

Screenshot

帖子截图

Support Level

活跃: 10up 正在积极致力于这个,我们希望在可预见的未来继续工作,包括保持对最新版本 WordPress 的测试。 欢迎错误报告、功能请求、问题和请求请求。

Changelog

CHANGELOG.md 中记录了对 ElasticPress React 组件的所有显着更改的完整列表。

Contributing

请阅读 CODEOFCONDUCT.md 了解我们的详细信息行为准则,CONTRIBUTING.md 有关向我们提交拉取请求的流程的详细信息和 CREDITS.md 用于维护者、贡献者和使用的库的列表由 ElasticPress React 组件组成。

Like what you see?

10up 与我们一起工作

ElasticPress React

ElasticPress React is a library of React components to supercharge your headless WordPress website with ElasticPress.

Support LevelRelease VersionGPLv2 License

Requirements

Installation

To install ElasticPress React, simply install via npm:

npm install @10up/elasticpress-react --save

You will need an Elasticsearch instance and a WordPress website running ElasticPress.

Components

ElasticPressProvider

You must wrap your application with ElasticPressProvider in order to use the ElasticPress components.

    <ElasticPressProvider
        node="http://elasticpress.test/__elasticsearch"
        indexName="elasticpresstest-post-1"
    >
        {/* ElasticPress Components */}
    </ElasticPressProvider>

Autosuggest

This component outputs a search field that when typed in will autosuggest results to the user.

import { AutosuggestField } from '@10up/elasticpress-react';

const MyComponent = () => (
    <>
        <p>Here is my fancy new component.</p>

        <p>Here's a search input with autosuggest:</p>

        <ElasticPressProvider
                node="http://elasticpress.test/__elasticsearch"
                indexName="elasticpresstest-post-1"
                loadInitialData={false}
            >
                <AutosuggestField />
            </ElasticPressProvider>
    </>
);

Screenshot

Autosuggest screenshot

Related Content

This component outputs content related to a post.

import { RelatedContent } from '@10up/elasticpress-react';

const MyComponent = () => (
    <>
        <p>Here is my fancy new component.</p>

        <p>Here is some related content to post 5:</p>

        <RelatedContent
            wpApiRoot="https://mysite.com/wp-json"
            postId="5"
        />
    </>
);

Search and Post Results

import { PostContextProvider, SearchField, Posts } from '@10up/elasticpress-react';

const MyComponent = () => {
    // Make sure to wrap your components with the provider.
    return (
        <ElasticPressProvider
            node="http://elasticpress.test/__elasticsearch"
            indexName="elasticpresstest-post-1"
        >
            <div>
                <SearchField />
            </div>

            <div>
                <Posts />
            </div>
        </ElasticPressProvider>
    );
};

Screenshot

Posts screenshot

Support Level

Active: 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome.

Changelog

A complete listing of all notable changes to ElasticPress React components are documented in CHANGELOG.md.

Contributing

Please read CODEOFCONDUCT.md for details on our code of conduct, CONTRIBUTING.md for details on the process for submitting pull requests to us, and CREDITS.md for a listing of maintainers of, contributors to, and libraries used by ElasticPress React components.

Like what you see?

Work with us at 10up

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文