Skip to content

Conversation

@Fran-A-Dev
Copy link
Contributor

…er results with markdown

SearchBar Component:
    Added react-markdown for rendering markdown content in search result excerpts.
    Enhanced the search bar to allow user queries and display results dynamically.
    Fixed the search result paths to link correctly to markdown pages, removing unnecessary path redundancies.
    Ensured the modal can be opened/closed via buttons and keyboard events, with better accessibility features.

lib/search.js:
    Created a recursive function to fetch markdown files, including nested ones.
    Extracted metadata from markdown files (using eval) and removed the metadata block from content before indexing.
    Corrected the file paths for Next.js routing by removing pages and cleaning up paths like /index.
    Added markdown content and metadata indexing using Lunr.js for efficient full-text search capabilities.

pages/api/search.js:
    Set up a search API using Lunr.js for client-side requests.
    Utilized the createIndex() function to generate and store an index for markdown documentation.
    Optimized the API response to return document titles, excerpts, and cleaned URLs for rendering search results on the client-side.

Dependencies:
    Installed lodash for utility functions (though not directly referenced in the code provided).
    Installed react-markdown for rendering markdown in search result excerpts.

…er results with markdown

    SearchBar Component:
        Added react-markdown for rendering markdown content in search result excerpts.
        Enhanced the search bar to allow user queries and display results dynamically.
        Fixed the search result paths to link correctly to markdown pages, removing unnecessary path redundancies.
        Ensured the modal can be opened/closed via buttons and keyboard events, with better accessibility features.

    lib/search.js:
        Created a recursive function to fetch markdown files, including nested ones.
        Extracted metadata from markdown files (using eval) and removed the metadata block from content before indexing.
        Corrected the file paths for Next.js routing by removing pages and cleaning up paths like /index.
        Added markdown content and metadata indexing using Lunr.js for efficient full-text search capabilities.

    pages/api/search.js:
        Set up a search API using Lunr.js for client-side requests.
        Utilized the createIndex() function to generate and store an index for markdown documentation.
        Optimized the API response to return document titles, excerpts, and cleaned URLs for rendering search results on the client-side.

    Dependencies:
        Installed lodash for utility functions (though not directly referenced in the code provided).
        Installed react-markdown for rendering markdown in search result excerpts.
Copy link
Member

@moonmeister moonmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work. needs some fine tuning but looks like it'll work well

import { gql, useQuery } from "@apollo/client";
import React, { useState, useEffect, useRef } from "react";
import { MagnifyingGlassIcon } from "@heroicons/react/24/solid";
import ReactMarkdown from "react-markdown"; // For rendering markdown excerpts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this conversion on the api or at build time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, let me find out.

import { MagnifyingGlassIcon } from "@heroicons/react/24/solid";
import ReactMarkdown from "react-markdown"; // For rendering markdown excerpts

const DOC_SEARCH_QUERY = gql`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will still need out search to cover blog posts, yeah? Should we setup search to do both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, we could or should we setup Smart Search for the WP side of things?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can decide this after our meeting tomorrow.


export default function handler(req, res) {
if (!indexData) {
indexData = createIndex(); // Get both index and documents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely against this being done at run time, and if we want to directly integrate WP data into this it makes sense. That said I'm not seeing any kind of cache purging or cache tags to put this in a CDN

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, if this can just be a static json file or at least that can be the case for the MDX data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that sounds good to me.

Copy link
Member

@moonmeister moonmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, needs changes, hit the wrong button

@moonmeister moonmeister marked this pull request as draft October 28, 2024 20:22
@moonmeister
Copy link
Member

moonmeister commented Nov 14, 2024

Closing in favor of #162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants