Compare commits

..
2 Commits
2 changed files with 19 additions and 2 deletions
+18 -1
View File
@@ -15,6 +15,23 @@ export interface IChatMessage {
sources?: IChatSource[]; sources?: IChatSource[];
} }
function stripNumericPrefixes(p: string): string {
return p
.split('/')
.map((seg) => seg.replace(/^\d+-/, ''))
.join('/');
}
export function sourceToUrl(file: string, anchor: string): string { export function sourceToUrl(file: string, anchor: string): string {
return `/${file}${anchor ? `#${anchor}` : ''}`; let p = file.replace(/^docs\//, '').replace(/\.md$/, '');
p = stripNumericPrefixes(p);
return `/docs/${p}${anchor ? `#${anchor}` : ''}`;
}
export function sourceToPath(file: string): string {
const p = file.replace(/^docs\//, '').replace(/\.md$/, '');
return stripNumericPrefixes(p);
} }
+1 -1
View File
@@ -32,7 +32,7 @@ export function Message({ role, content, sources }: MessageProps): ReactNode {
to={sourceToUrl(src.file, src.anchor)} to={sourceToUrl(src.file, src.anchor)}
className={b('sourceLink')} className={b('sourceLink')}
> >
{src.heading} {src.heading || sourceToPath(src.file)}
</Link> </Link>
))} ))}
</div> </div>