add line numbers

This commit is contained in:
hsjobeki 2023-02-08 14:49:11 +01:00
parent c48ae11b44
commit 1e29e826c7
4 changed files with 7 additions and 6 deletions

View File

@ -28,7 +28,7 @@ interface PreviewProps {
export const Preview = (props: PreviewProps) => {
const { docItem, handleClose, closeComponent = undefined } = props;
const { name, description, category, example, fn_type, id } = docItem;
const { name, description, category, example, fn_type, id, line } = docItem;
const theme = useTheme();
const prefix = category.split(/([\/.])/gm).at(4) || "builtins";
@ -120,7 +120,7 @@ export const Preview = (props: PreviewProps) => {
href={`https://github.com/NixOS/nixpkgs/blob/master/${category.replace(
"./",
""
)}`}
)}#L${line}`}
>
{"github:NixOS/nixpkgs/" + category.replace("./", "")}
</MuiLink>

View File

@ -315,11 +315,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1675353900,
"narHash": "sha256-8wc6dvfIcoEFKNBB8D2l32+TjXuBsj/AKnTqvINl6yY=",
"lastModified": 1675862788,
"narHash": "sha256-TS8YpNtYKBWP6xXrJ7DIdmJwwcCq0Tuf9NhQYWXoPXA=",
"owner": "hsjobeki",
"repo": "nixdoc",
"rev": "057981e5c53313e40824f05c82249cf0d2a5b552",
"rev": "76276fdb30ab4fcbe7ba19844a2afd9447256674",
"type": "github"
},
"original": {

View File

@ -16,6 +16,7 @@ export type DocItem = {
fn_type?: null | string;
description?: null | string | string[];
example?: null | string | string[];
line?: null | number;
};
export type MetaData = DocItem[];

View File

@ -6,7 +6,7 @@ export const byQuery =
const term = rawTerm.toLowerCase();
return data.reduce((results: (DocItem & {relevance: number})[], docItem: DocItem)=>{
const matchesOn = Object.keys(docItem).filter(key=>{
const rawValue = docItem[key as keyof DocItem];
const rawValue = String(docItem[key as keyof DocItem]);
if(rawValue === null || rawValue === undefined){
return false;
}