Skip to content

Commit

Permalink
Merge pull request #14 from coursetexts/fix-search
Browse files Browse the repository at this point in the history
Fix search
  • Loading branch information
genthegreat authored Feb 8, 2025
2 parents 7ffcfd8 + cd763eb commit 0e1d9a6
Show file tree
Hide file tree
Showing 11 changed files with 3,872 additions and 12,225 deletions.
17 changes: 13 additions & 4 deletions components/NotionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,22 @@ export const NotionPage: React.FC<types.PageProps> = ({
})
// Select all elements with the class 'notion-link'
const notionLinks = document.querySelectorAll('.notion-link')
console.log('notionLinks', notionLinks)

// Iterate through each notion-link
notionLinks.forEach((notionLink) => {
// Check if the parent of the notion-link has the 'custom-wrapper-class'
const parentWrapper = notionLink.closest('.custom-wrapper-class')

if (parentWrapper) {
// Clean up the page title text if it exists
const pageTitleText = notionLink.querySelector('.notion-page-title-text')
if (pageTitleText) {
pageTitleText.textContent = pageTitleText.textContent
.replace(/[_.]/g, ' ') // Replace underscores and dots with spaces
.trim() // Remove extra whitespace
}

// Check if the element is already wrapped with the 'notion-text' class
if (!notionLink.parentElement.classList.contains('notion-text')) {
// Create a new div with the class 'notion-text'
Expand All @@ -363,8 +372,8 @@ export const NotionPage: React.FC<types.PageProps> = ({
}
}
})
//
function removeNearestContainersForLink(linkHref) {

const removeNearestContainersForLink = (linkHref: string) => {
document.querySelectorAll(`a[href="${linkHref}"]`).forEach((link) => {
let container = link.closest('div') as HTMLElement // Find the nearest container (first parent div)
let count = 0 // Track how many containers are removed
Expand All @@ -377,7 +386,7 @@ export const NotionPage: React.FC<types.PageProps> = ({
}
})
}
// Usage:

removeNearestContainersForLink(
'https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en'
)
Expand Down Expand Up @@ -409,7 +418,7 @@ export const NotionPage: React.FC<types.PageProps> = ({

// Replace the inner HTML with only the text content
summaryElement.innerHTML = textContent
})
})
} else {
//
document.querySelectorAll('.notion-title').forEach(function (summary) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const navigationLinks: Array<NavigationLink | null> = getSiteConfig(
)

// Optional site search
export const isSearchEnabled: boolean = getSiteConfig('isSearchEnabled', true)
export const isSearchEnabled: boolean = getSiteConfig('isSearchEnabled', true);

// ----------------------------------------------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions lib/get-site-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getAllPagesInSpace, uuidToId, getPageProperty } from 'notion-utils'
import pMemoize from 'p-memoize'
import { ExtendedRecordMap } from 'notion-types'

import * as config from './config'
import * as types from './types'
Expand Down Expand Up @@ -29,15 +30,15 @@ async function getAllPagesImpl(
rootNotionPageId: string,
rootNotionSpaceId: string
): Promise<Partial<types.SiteMap>> {
const getPage = async (pageId: string, ...args) => {
const getPage = async (pageId: string): Promise<ExtendedRecordMap> => {
console.log('\nnotion getPage', uuidToId(pageId))
return notion.getPage(pageId, ...args)
return notion.getPage(pageId)
}

const pageMap = await getAllPagesInSpace(
rootNotionPageId,
rootNotionSpaceId,
getPage
getPage as any // Using type assertion to bypass the type conflict
)

const canonicalPageMap = Object.keys(pageMap).reduce(
Expand Down
2 changes: 1 addition & 1 deletion lib/notion-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NotionAPI } from 'notion-client'
import { NotionAPI } from '@genthegreat/notion-client'

export const notion = new NotionAPI({
apiBaseUrl: process.env.NOTION_API_BASE_URL
Expand Down
Loading

0 comments on commit 0e1d9a6

Please sign in to comment.