Spaces:
Running
Running
fix bibtex truncated title
Browse files- app/src/pages/index.astro +11 -9
app/src/pages/index.astro
CHANGED
|
@@ -11,8 +11,14 @@ import 'katex/dist/katex.min.css';
|
|
| 11 |
import '../styles/global.css';
|
| 12 |
const articleFM = (ArticleMod as any).frontmatter ?? {};
|
| 13 |
const Article = (ArticleMod as any).default;
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
const docTitleHtml = (articleFM?.title ?? 'Untitled article')
|
| 17 |
.replace(/\\n/g, '<br/>')
|
| 18 |
.replace(/\n/g, '<br/>');
|
|
@@ -96,12 +102,8 @@ const imageAbs: string = fmOg && fmOg.startsWith('http')
|
|
| 96 |
|
| 97 |
// ---- Build citation text & BibTeX from frontmatter ----
|
| 98 |
const stripHtml = (text: string) => String(text || '').replace(/<[^>]*>/g, '');
|
| 99 |
-
|
| 100 |
-
const titleFlat = stripHtml(
|
| 101 |
-
.replace(/\\n/g, ' ')
|
| 102 |
-
.replace(/\n/g, ' ')
|
| 103 |
-
.replace(/\s+/g, ' ')
|
| 104 |
-
.trim();
|
| 105 |
const extractYear = (val: string | undefined): number | undefined => {
|
| 106 |
if (!val) return undefined;
|
| 107 |
const d = new Date(val);
|
|
@@ -116,7 +118,7 @@ const citationText = `${citationAuthorsText}${year ? ` (${year})` : ''}. "${titl
|
|
| 116 |
|
| 117 |
const authorsBib = authorNames.join(' and ');
|
| 118 |
const keyAuthor = (authorNames[0] || 'article').split(/\s+/).slice(-1)[0].toLowerCase();
|
| 119 |
-
const keyTitle = titleFlat.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '')
|
| 120 |
const bibKey = `${keyAuthor}${year ?? ''}_${keyTitle}`;
|
| 121 |
const doi = (ArticleMod as any)?.frontmatter?.doi ? String((ArticleMod as any).frontmatter.doi) : undefined;
|
| 122 |
const bibtex = `@misc{${bibKey},\n title={${titleFlat}},\n author={${authorsBib}},\n ${year ? `year={${year}},\n ` : ''}${doi ? `doi={${doi}}` : ''}\n}`;
|
|
|
|
| 11 |
import '../styles/global.css';
|
| 12 |
const articleFM = (ArticleMod as any).frontmatter ?? {};
|
| 13 |
const Article = (ArticleMod as any).default;
|
| 14 |
+
// Clean version without <br/> for metadata, SEO, citations
|
| 15 |
+
const docTitle = (articleFM?.title ?? 'Untitled article')
|
| 16 |
+
.replace(/<br\s*\/?>/gi, ' ')
|
| 17 |
+
.replace(/\\n/g, ' ')
|
| 18 |
+
.replace(/\n/g, ' ')
|
| 19 |
+
.replace(/\s+/g, ' ')
|
| 20 |
+
.trim();
|
| 21 |
+
// HTML version with <br/> for Hero H1 display only
|
| 22 |
const docTitleHtml = (articleFM?.title ?? 'Untitled article')
|
| 23 |
.replace(/\\n/g, '<br/>')
|
| 24 |
.replace(/\n/g, '<br/>');
|
|
|
|
| 102 |
|
| 103 |
// ---- Build citation text & BibTeX from frontmatter ----
|
| 104 |
const stripHtml = (text: string) => String(text || '').replace(/<[^>]*>/g, '');
|
| 105 |
+
// Use docTitle (already cleaned) and strip any remaining HTML for BibTeX
|
| 106 |
+
const titleFlat = stripHtml(docTitle);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
const extractYear = (val: string | undefined): number | undefined => {
|
| 108 |
if (!val) return undefined;
|
| 109 |
const d = new Date(val);
|
|
|
|
| 118 |
|
| 119 |
const authorsBib = authorNames.join(' and ');
|
| 120 |
const keyAuthor = (authorNames[0] || 'article').split(/\s+/).slice(-1)[0].toLowerCase();
|
| 121 |
+
const keyTitle = titleFlat.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '');
|
| 122 |
const bibKey = `${keyAuthor}${year ?? ''}_${keyTitle}`;
|
| 123 |
const doi = (ArticleMod as any)?.frontmatter?.doi ? String((ArticleMod as any).frontmatter.doi) : undefined;
|
| 124 |
const bibtex = `@misc{${bibKey},\n title={${titleFlat}},\n author={${authorsBib}},\n ${year ? `year={${year}},\n ` : ''}${doi ? `doi={${doi}}` : ''}\n}`;
|