Skip to content

Commit

Permalink
update bibliography
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-wojahn committed Nov 19, 2024
1 parent ea13210 commit 5543782
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 27 deletions.
197 changes: 170 additions & 27 deletions docs/assets/js/zotero-bibliography.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ZoteroBibliography extends HTMLElement {

async loadBibliography() {
try {
const response = await fetch('https://api.zotero.org/groups/5751974/items/top?format=json&limit=100&v=3', {
const response = await fetch('https://api.zotero.org/groups/5751974/items/top?format=json&limit=100&v=3&include=data,bib', {
headers: { 'Accept': 'application/json' },
mode: 'cors'
});
Expand Down Expand Up @@ -62,13 +62,14 @@ class ZoteroBibliography extends HTMLElement {
<style>
.bibliography-container {
font-family: var(--md-text-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
max-width: 100%;
}
.filters {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
padding: 1rem;
padding: 1.5rem;
background: var(--md-code-bg-color, #f5f5f5);
border-radius: 4px;
}
Expand All @@ -82,52 +83,93 @@ class ZoteroBibliography extends HTMLElement {
color: var(--md-typeset-color, #333);
}
select, input {
padding: 0.5rem;
padding: 0.75rem;
border: 1px solid var(--md-typeset-table-color, #ddd);
border-radius: 4px;
background: var(--md-default-bg-color, #fff);
color: var(--md-typeset-color, #333);
font-size: 0.9rem;
}
.bib-item {
margin-bottom: 1.5rem;
padding: 1rem;
border-left: 3px solid var(--md-primary-fg-color, #2196f3);
margin-bottom: 2rem;
padding: 1.5rem;
border: 1px solid var(--md-typeset-table-color, #ddd);
border-radius: 4px;
background: var(--md-default-bg-color, #fff);
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.bib-title {
font-size: 1.1rem;
font-weight: 600;
color: var(--md-typeset-color, #333);
margin-bottom: 0.5rem;
margin-bottom: 0.75rem;
line-height: 1.4;
}
.bib-authors {
font-style: italic;
color: var(--md-default-fg-color--light, #666);
margin-bottom: 0.5rem;
margin-bottom: 0.75rem;
line-height: 1.4;
}
.bib-meta {
font-size: 0.9rem;
color: var(--md-default-fg-color--lighter, #888);
color: var(--md-default-fg-color--light, #666);
line-height: 1.6;
}
.bib-links {
margin-top: 0.75rem;
}
.bib-links a {
display: inline-block;
padding: 0.4rem 0.8rem;
margin-right: 0.5rem;
margin-bottom: 0.5rem;
background: var(--md-primary-fg-color--light, #5e9eff);
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 0.8rem;
transition: background-color 0.2s;
}
.bib-links a:hover {
background: var(--md-primary-fg-color, #2196f3);
}
.bib-tags {
margin-top: 0.5rem;
margin-top: 1rem;
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
.tag {
padding: 0.2rem 0.5rem;
padding: 0.3rem 0.6rem;
background: var(--md-code-bg-color, #f5f5f5);
border-radius: 4px;
font-size: 0.8rem;
color: var(--md-default-fg-color, #666);
}
.results-count {
margin-bottom: 1rem;
margin-bottom: 1.5rem;
font-style: italic;
color: var(--md-default-fg-color--light, #666);
}
.tibetan {
font-family: "Noto Sans Tibetan", "Microsoft Himalaya", sans-serif;
font-size: 1.1em;
}
.publication-type {
display: inline-block;
padding: 0.2rem 0.5rem;
background: var(--md-code-bg-color, #f5f5f5);
border-radius: 4px;
font-size: 0.8rem;
color: var(--md-default-fg-color--light, #666);
margin-bottom: 0.5rem;
}
@media (max-width: 600px) {
.filters {
grid-template-columns: 1fr;
}
}
</style>
<div class="bibliography-container">
<div class="filters">
Expand All @@ -137,7 +179,7 @@ class ZoteroBibliography extends HTMLElement {
<option value="all">All Types</option>
${types.map(type => `
<option value="${type}" ${this.filters.type === type ? 'selected' : ''}>
${type.charAt(0).toUpperCase() + type.slice(1)}
${this.formatItemType(type)}
</option>
`).join('')}
</select>
Expand Down Expand Up @@ -171,30 +213,131 @@ class ZoteroBibliography extends HTMLElement {
this.attachEventListeners();
}

formatItemType(type) {
return type
.replace(/([A-Z])/g, ' $1')
.replace(/^./, str => str.toUpperCase());
}

renderItem(data) {
const mainTitle = this.formatTibetanText(data.title);
const shortTitle = data.shortTitle ? this.formatTibetanText(data.shortTitle) : '';

return `
<div class="bib-item">
<div class="bib-title">${data.title}</div>
<div class="publication-type">${this.formatItemType(data.itemType)}</div>
<div class="bib-title">${mainTitle}</div>
${shortTitle ? `<div class="bib-title tibetan">${shortTitle}</div>` : ''}
<div class="bib-authors">
${(data.creators || [])
.map(c => `${c.lastName || ''}, ${c.firstName || ''}`.trim())
.join('; ')}
${this.formatAuthors(data.creators)}
</div>
<div class="bib-meta">
${data.date ? `${data.date}` : ''}
${data.publicationTitle ? `in ${data.publicationTitle}` : ''}
${data.DOI ? `<br>DOI: <a href="https://doi.org/${data.DOI}" target="_blank">${data.DOI}</a>` : ''}
${data.url ? `<br><a href="${data.url}" target="_blank">View online →</a>` : ''}
${this.formatMetadata(data)}
</div>
${data.tags && data.tags.length ? `
<div class="bib-tags">
${data.tags.map(tag => `<span class="tag">${tag.tag}</span>`).join('')}
</div>
` : ''}
${this.formatLinks(data)}
${this.formatTags(data.tags)}
</div>
`;
}

formatTibetanText(text) {
if (!text) return '';
// Check if the text contains Tibetan characters
if (/[\u0F00-\u0FFF]/.test(text)) {
return `<span class="tibetan">${text}</span>`;
}
return text;
}

formatAuthors(creators) {
if (!creators || creators.length === 0) return '';

const authors = creators
.filter(creator => creator.creatorType === 'author' || creator.creatorType === 'editor')
.map(creator => {
const name = creator.firstName ?
`${creator.lastName}, ${creator.firstName}` :
this.formatTibetanText(creator.lastName);
return `${name}${creator.creatorType === 'editor' ? ' (ed.)' : ''}`;
});

if (authors.length === 0) return '';
if (authors.length === 1) return authors[0];
if (authors.length === 2) return `${authors[0]} & ${authors[1]}`;
return `${authors[0]} et al.`;
}

formatMetadata(data) {
const parts = [];

if (data.date) {
parts.push(`<strong>${data.date.split('-')[0]}</strong>`);
}

if (data.publicationTitle) {
parts.push(`in <em>${this.formatTibetanText(data.publicationTitle)}</em>`);
}

if (data.publisher) {
parts.push(this.formatTibetanText(data.publisher));
}

if (data.place) {
parts.push(data.place);
}

if (data.volume) {
parts.push(`Vol. ${data.volume}`);
}

if (data.issue) {
parts.push(`No. ${data.issue}`);
}

if (data.pages) {
parts.push(`pp. ${data.pages}`);
}

return parts.join(', ');
}

formatTags(tags) {
if (!tags || tags.length === 0) return '';

return `
<div class="bib-tags">
${tags.map(tag => `
<span class="tag">${this.formatTibetanText(tag.tag)}</span>
`).join('')}
</div>
`;
}

formatLinks(data) {
const links = [];

if (data.DOI) {
links.push(`<a href="https://doi.org/${encodeURIComponent(data.DOI)}" target="_blank" rel="noopener noreferrer">DOI</a>`);
}

if (data.url) {
links.push(`<a href="${data.url}" target="_blank" rel="noopener noreferrer">View Online</a>`);
}

if (data.abstractNote) {
links.push(`
<details>
<summary>Abstract</summary>
<p style="margin-top: 0.5rem; line-height: 1.6;">
${this.formatTibetanText(data.abstractNote)}
</p>
</details>
`);
}

return links.length > 0 ? `<div class="bib-links">${links.join('')}</div>` : '';
}

attachEventListeners() {
const typeFilter = this.querySelector('#type-filter');
const yearFilter = this.querySelector('#year-filter');
Expand Down
File renamed without changes.

0 comments on commit 5543782

Please sign in to comment.