npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

search-engine-wc

v0.2.2

Published

Web component to search content in different pages

Downloads

460

Readme

<search-engine-wc />

npm version npm size

This Web Component allows you to have a search engine similar to Vitepress easily in any framework (React, Brisa, Vue, Solid.js, Svelte, Vanilla JS, etc).

Includes:

🔗 Demo

Getting Started

In any framework except Brisa

Add these scripts into your <head>:

<script type="importmap">
  {
    "imports": {
      "brisa/client": "https://unpkg.com/brisa@latest/client-simplified/index.js"
    }
  }
</script>
<script type="module" src="https://unpkg.com/search-engine-wc@latest"></script>

Alternatively, you can install it via npm:

npm install search-engine-wc

And then import it in your code:

import "search-engine-wc";

[!NOTE]

You need to add the importmap for brisa/client. All the web components made with Brisa need this wrapper to run, the good thing is that if you have other WC made with Brisa you won't need again to add the 3kb that brisa/client occupies.

SSR

Pre-requisites: You need to have Brisa installed.

For SSR you can use the renderToString function from brisa/server:

import { renderToString } from "brisa/server";
import { jsx } from "brisa/jsx-runtime";
import SearchEngineWC from "search-engine-wc/server";

const jsonUrl = "/demo.json";
const htmlString = await renderToString(jsx(SearchEngineWC, { jsonUrl }));

In Brisa Framework

First install:

bun add search-engine-wc --save --exact

Then import it in your src/web-components/_integrations.ts file:

import type { WebComponentIntegrations } from "brisa";

export default {
  "search-engine-wc": {
    client: "search-engine-wc",
    server: "search-engine-wc/server",
    types: "search-engine-wc/types",
  },
} satisfies WebComponentIntegrations;

Usage

<search-engine-wc jsonUrl="/demo.json" />

To work properly you have to provide a JSON with all the sections of your pages.

[
  {
    "id": "/blog/introduction#what-is-this-blog",
    "title": "Introduction",
    "text": "Welcome to the blog! In this section, we explain what this blog is about...",
    "titles": ["Introduction", "What is this blog?"]
  },
  {
    "id": "/blog/introduction#why-start-blogging",
    "title": "Why Start Blogging",
    "text": "Blogging is a powerful way to share ideas...",
    "titles": ["Introduction", "Why Start Blogging"]
  },
  {
    "id": "/blog/web-development#frontend-vs-backend",
    "title": "Frontend vs Backend",
    "text": "In web development, there are two main parts: frontend and backend...",
    "titles": ["Web Development", "Frontend vs Backend"]
  },
  {
    "id": "/blog/web-development#css-tricks",
    "title": "CSS Tricks",
    "text": "Here are some advanced CSS tricks that will help you in your projects...",
    "titles": ["Web Development", "CSS Tricks"]
  },
  {
    "id": "/blog/javascript-basics#variables-and-scope",
    "title": "Variables and Scope",
    "text": "Understanding variables and scope is fundamental to JavaScript...",
    "titles": ["JavaScript Basics", "Variables and Scope"]
  },
  {
    "id": "/blog/javascript-basics#arrow-functions",
    "title": "Arrow Functions",
    "text": "Arrow functions are a shorter way to write functions in JavaScript...",
    "titles": ["JavaScript Basics", "Arrow Functions"]
  },
  {
    "id": "/blog/css-grid#layout-with-css-grid",
    "title": "Layout with CSS Grid",
    "text": "CSS Grid is a powerful tool for creating two-dimensional layouts...",
    "titles": ["CSS Grid", "Layout with CSS Grid"]
  },
  {
    "id": "/blog/css-grid#responsive-design",
    "title": "Responsive Design",
    "text": "Designing responsive layouts is key in modern web development...",
    "titles": ["CSS Grid", "Responsive Design"]
  },
  {
    "id": "/blog/seo#on-page-seo",
    "title": "On-Page SEO",
    "text": "Optimizing your website's content is crucial for on-page SEO...",
    "titles": ["SEO", "On-Page SEO"]
  },
  {
    "id": "/blog/seo#technical-seo",
    "title": "Technical SEO",
    "text": "Technical SEO involves optimizing the infrastructure of your site...",
    "titles": ["SEO", "Technical SEO"]
  },
  {
    "id": "/blog/advanced-javascript#promises-and-async-await",
    "title": "Promises and Async/Await",
    "text": "Promises and async/await simplify asynchronous programming in JavaScript...",
    "titles": ["Advanced JavaScript", "Promises and Async/Await"]
  },
  {
    "id": "/blog/advanced-javascript#closures",
    "title": "Closures",
    "text": "Closures are a key concept in JavaScript that allow functions to access variables...",
    "titles": ["Advanced JavaScript", "Closures"]
  }
]

Props

  • jsonUrl: The URL of the JSON file with all the sections of your pages.
  • maxResults: The maximum number of results to show. (Default: 15)

CSS Variables

--search-engine-color: #07645a
  /* The color of the text (borders are derived colors from this) */;

[!NOTE]

Dark mode is supported by default with the color-scheme css property (light / dark).

Types

export default function SearchEngineWC(props: {
  jsonUrl: string;
  maxResults?: number;
}): JSX.Element;

Notes for Contributors

Good to know:

  1. The code is inside src/web-components/search-engine-wc.tsx, the other files from src is for the demo.
  2. bun run build do the build of both (demo + web component).
  3. bun dev you can preview the WC inside the demo on https://localhost:3000.

License

MIT