BibliographyBackbone: Difference between revisions

From Illustrations in German Translations of Mark Twain's Works

No edit summary
No edit summary
Line 39: Line 39:
     };
     };
     return text.replace(/[&<>"']/g, m => map[m]);
     return text.replace(/[&<>"']/g, m => map[m]);
  }
  function getOrUnknown(value) {
    if (!value || (typeof value === 'string' && !value.trim())) {
      return 'unknown';
    }
    return value;
   }
   }


   function formatAuthors(authors) {
   function formatAuthors(authors) {
     if (!authors || authors.length === 0) return '';
     if (!authors || authors.length === 0) {
      return 'unknown';
    }
   
     if (authors.length === 1) {
     if (authors.length === 1) {
       const a = authors[0];
       const a = authors[0];
       return a.given ? `${a.family}, ${a.given}` : a.family;
       const family = a.family || 'unknown';
      const given = a.given || '';
      return given ? `${family}, ${given}` : family;
     }
     }
   
     if (authors.length === 2) {
     if (authors.length === 2) {
       const a1 = authors[0];
       const a1 = authors[0];
       const a2 = authors[1];
       const a2 = authors[1];
       const name1 = a1.given ? `${a1.family}, ${a1.given}` : a1.family;
       const name1 = (a1.family || 'unknown') + (a1.given ? ', ' + a1.given : '');
       const name2 = a2.given ? `${a2.family}, ${a2.given}` : a2.family;
       const name2 = (a2.family || 'unknown') + (a2.given ? ', ' + a2.given : '');
       return `${name1}, and ${name2}`;
       return `${name1}, and ${name2}`;
     }
     }
     const a = authors[0];
     const a = authors[0];
     const name = a.given ? `${a.family}, ${a.given}` : a.family;
     const name = (a.family || 'unknown') + (a.given ? ', ' + a.given : '');
     return `${name}, et al.`;
     return `${name}, et al.`;
   }
   }
Line 63: Line 77:


     // Autoren
     // Autoren
     if (entry.authors && entry.authors.length > 0) {
     const authors = formatAuthors(entry.authors);
      citation += formatAuthors(entry.authors) + '. ';
    citation += authors + '. ';
    }


     // Titel
     // Titel
     if (entry.title) {
     const title = getOrUnknown(entry.title);
      if (entry.type === 'bookSection' || entry.type === 'book') {
    if (entry.type === 'bookSection' || entry.type === 'book') {
        citation += `<i>${escapeHtml(entry.title)}</i>. `;
      citation += `<i>${escapeHtml(title)}</i>. `;
      } else {
    } else {
        citation += `"${escapeHtml(entry.title)}." `;
      citation += `"${escapeHtml(title)}." `;
      }
     }
     }


     // Container
     // Container
     if (entry.container) {
    const container = entry.container;
       citation += `<i>${escapeHtml(entry.container)}</i>. `;
     if (container && container.trim()) {
       citation += `<i>${escapeHtml(container)}</i>. `;
     }
     }


     // Jahr
     // Jahr
     if (entry.year) {
     const year = getOrUnknown(entry.year);
      citation += `${entry.year}. `;
    citation += `${year}. `;
    }


     // URL
     // URL
     if (entry.url) {
     if (entry.url && entry.url.trim()) {
       citation += `<a href="${escapeHtml(entry.url)}" target="_blank">${escapeHtml(entry.url)}</a>.`;
       citation += `<a href="${escapeHtml(entry.url)}" target="_blank">${escapeHtml(entry.url)}</a>.`;
     } else {
     } else {
Line 100: Line 112:


   function generateTagsAttribute(tags) {
   function generateTagsAttribute(tags) {
     if (!tags || tags.length === 0) return '';
     if (!tags || tags.length === 0) {
      return ' data-tags="untagged"';
    }
     const normalized = tags
     const normalized = tags
       .map(tag => tag.toLowerCase().replace(/\s+/g, '_'))
       .map(tag => tag.toLowerCase().replace(/\s+/g, '_'))
Line 108: Line 122:


   function generateTagSpans(tags) {
   function generateTagSpans(tags) {
     if (!tags || tags.length === 0) return '';
     if (!tags || tags.length === 0) {
      return '<span class="tag" data-tag="untagged">untagged</span>';
    }
     return tags
     return tags
       .map(tag => {
       .map(tag => {
Line 121: Line 137:
     const tagsAttr = generateTagsAttribute(entry.tags);
     const tagsAttr = generateTagsAttribute(entry.tags);
     const tagSpans = generateTagSpans(entry.tags);
     const tagSpans = generateTagSpans(entry.tags);
     const abstract = entry.abstract ? escapeHtml(entry.abstract) : '';
     const abstract = entry.abstract && entry.abstract.trim() ? escapeHtml(entry.abstract) : '';


     return `<!-- ${index} -->
     return `<!-- ${index} -->

Revision as of 00:49, 12 May 2026

Bibliography Generator