Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/SearchBar/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
font-size: 0.8em;
}

.description {
display: block;
margin-top: 5px;
color: var(--theme-color-disabled);
font-size: 0.85em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.search-container > button,
.search-icon {
position: absolute;
Expand Down
5 changes: 4 additions & 1 deletion src/components/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const SearchBar = () => {
<span className={styles.provider}>{name}</span> {searchTerm}
</a>
))}
{results.map(({ name, url, featured, link }, index) => (
{results.map(({ name, url, featured, link, description }, index) => (
<a
key={index}
href={url}
Expand All @@ -151,6 +151,9 @@ const SearchBar = () => {
)}
{name}
<span className={styles.url}>{url}</span>
{description && (
<span className={styles.description}>{description}</span>
)}
</a>
))}
</div>
Expand Down
10 changes: 6 additions & 4 deletions src/components/SearchBar/useSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const useSearch = (searchTerm: string, config?: ConfigEntity) => {
if (config && config.featured) {
list.push(
...config.featured.map((link, index) => {
const { name, link: url, tags } = link
const { name, link: url, tags, description, desc } = link
return {
featured: true,
link,
searchText: [name, url, tags].join(' '),
description: description || desc,
searchText: [name, url, tags, description, desc].join(' '),
name,
url,
}
Expand All @@ -28,12 +29,13 @@ const useSearch = (searchTerm: string, config?: ConfigEntity) => {
if (config?.categories) {
config.categories.forEach((category, categoryIndex) => {
category.links.forEach((link, linkIndex) => {
const { name, link: url, tags } = link
const { name, link: url, tags, description, desc } = link

list.push({
featured: false,
link,
searchText: [name, url, tags].join(' '),
description: description || desc,
searchText: [name, url, tags, description, desc].join(' '),
name,
url,
})
Expand Down
1 change: 1 addition & 0 deletions src/components/SearchContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface SearchResult {
searchText: string
name: string
url: string
description?: string
}

interface ISearchContext {
Expand Down
6 changes: 6 additions & 0 deletions src/modules/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DEFAULT_LINK: LinksEntity = {
name: '',
link: '',
tags: '',
description: '',
target: '_blank',
}

Expand All @@ -32,6 +33,7 @@ export const DEFAULT_FEATURED_LINK: FeaturedEntity = {
link: '',
background: DEFAULT_BG,
tags: '',
description: '',
target: '_blank',
}

Expand All @@ -53,6 +55,8 @@ export const CONFIG_ENTITY_SCHEMA: JSONSchemaType<ConfigEntity> = {
name: { type: 'string' },
link: { type: 'string' },
tags: { type: 'string', nullable: true },
description: { type: 'string', nullable: true },
desc: { type: 'string', nullable: true },
background: { type: 'string', nullable: true },
target: { type: 'string', enum: ['_self', '_blank'], nullable: true },
},
Expand All @@ -73,6 +77,8 @@ export const CONFIG_ENTITY_SCHEMA: JSONSchemaType<ConfigEntity> = {
name: { type: 'string' },
link: { type: 'string' },
tags: { type: 'string', nullable: true },
description: { type: 'string', nullable: true },
desc: { type: 'string', nullable: true },
target: { type: 'string', enum: ['_self', '_blank'], nullable: true },
},
required: ['link', 'name'],
Expand Down
8 changes: 8 additions & 0 deletions src/modules/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export interface LinksEntity {
name: string
link: string
tags?: string
/**
* Optional longer text for a bookmark, used in search results.
*/
description?: string
/**
* Backward-compatible alias used by some configs.
*/
desc?: string
/**
* Where should the link open?
* Defaults to `_blank` to preserve existing behaviour.
Expand Down