Skip to content

Instantly share code, notes, and snippets.

@zepadovani
Last active February 18, 2025 11:05
Show Gist options
  • Select an option

  • Save zepadovani/cfa10ec91ac1192f3c6ea286e227d3d1 to your computer and use it in GitHub Desktop.

Select an option

Save zepadovani/cfa10ec91ac1192f3c6ea286e227d3d1 to your computer and use it in GitHub Desktop.
Better BibTex (zotero) postscript to include 'urlaccessdate' in the exported file (to use with abntex2cite)
/**
* Script para exportar corretamente a data de acesso de um item bibliográfico do Zotero utilizando Better BibTeX
* de maneira que, além do campo 'urldate' (com data ISO), seja exportado um campo 'urlaccessdate' com data em português
* (que é devidamente reconhecido pelo pacote abntex2cite. Para utilizar copie esse script no campo 'postscript' ]
* do Better BibTeX, no zotero. Certifique-se também de adicionar a exportação de url (após criar a exportação automática) e
* de reinserir os itens bibliográficos na coleção da bibliografia (parece que o Better BibTeX não reatualiza esse campo após o
* item ser criado.
*
* Script to correctly export the access date of a Zotero bibliographic item using Better BibTeX
* So that, in addition to the 'urldate' field (with ISO date), a 'urlaccessdate' field is exported with the date in Portuguese
* (Which is properly recognized by the abntex2cite package). To use, copy this script into the 'postscript' field
* of Better BibTeX in Zotero. Also, make sure to add the export of the URL (after creating the automatic export) and
* to re-insert the bibliographic items into the bibliography collection (it seems that Better BibTeX does not refresh this field after the item is created).
*/
function formatDateInPortuguese(dateString) {
// English: Formats a date string to "DD mmm YYYY" in Portuguese.
// Português: Formata uma string de data para "DD mmm AAAA" em português.
const date = new Date(dateString); // English: Parses ISO date string. / Português: Analisa a string de data ISO.
const day = date.getDate(); // English: Gets day of month. / Português: Obtém o dia do mês.
const month = date.getMonth(); // English: Gets month (0-indexed). / Português: Obtém o mês (indexado em 0).
const year = date.getFullYear(); // English: Gets full year. / Português: Obtém o ano completo.
// English: Portuguese month abbreviations. / Português: Abreviações dos meses em português.
const months_pt_BR = ['jan.', 'fev.', 'mar.', 'abr.', 'maio', 'jun.', 'jul.', 'ago.', 'set.', 'out.', 'nov.', 'dez.'];
const monthAbbr = months_pt_BR[month]; // English: Gets Portuguese month abbreviation. / Português: Obtém a abreviação do mês em português.
return `${day} ${monthAbbr} ${year}`; // English: Returns formatted date string. / Português: Retorna a string de data formatada.
}
if (Translator.BetterBibTeX && zotero.accessDate) {
// English: Checks if in Better BibTeX and has accessDate. / Português: Verifica se está no Better BibTeX e tem accessDate.
const formattedAccessDate = formatDateInPortuguese(zotero.accessDate); // English: Formats accessDate. / Português: Formata accessDate.
tex.add({ name: 'urlaccessdate', value: formattedAccessDate }); // English: Adds urlaccessdate field to BibTeX. / Português: Adiciona o campo urlaccessdate ao BibTeX.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment