def cite_me( doi: str = None, manual_ref: str = None, cite_text: str = "Cite me" ) -> html.Div: """ Create a button to show users how to cite a particular resource. :param doi: DOI :param manual_ref: If DOI not available :param cite_text: Text to show as button label :return: A button """ if doi: if doi in DOI_CACHE: ref = DOI_CACHE[doi] else: try: ref = content_negotiation(ids=doi, format="text", style="ieee")[3:] DOI_CACHE[doi] = ref dumpfn(DOI_CACHE, MODULE_PATH / "apps/assets/doi_cache.json") except Exception as exc: print("Error retrieving DOI", doi, exc) ref = f"DOI: {doi}" tooltip_text = f"If this analysis is useful, please cite {ref}" elif manual_ref: warnings.warn("Please use the DOI if available.") tooltip_text = ( f"If this analysis is useful, please cite the " f"relevant publication: {manual_ref}" ) else: tooltip_text = ( f"If this analysis is useful, please cite the " f"relevant publication (publication pending)." ) reference_button = html.A( [ Button( [Icon(kind="book"), html.Span(cite_text)], size="small", kind="link", style={"height": "1.5rem"}, ) ], href=f"https://dx.doi.org/{doi}", target="_blank", ) with_tooltip = get_tooltip(reference_button, tooltip_text, underline=False) return with_tooltip
def resolve(self, identifier): paper_meta = json.loads( habanero.content_negotiation(ids=identifier, format='citeproc-json')) return { "title": paper_meta['title'], "pubdate": process_pubdate(paper_meta['published-print']['date-parts'], "year", "month", "day"), "publisher": '{} {}'.format(paper_meta['publisher'], paper_meta['publisher-location']), "comments": paper_meta['container-title'], "authors": [ '{} {}'.format(author['given'], author['family']) for author in paper_meta['author'] ], "rating": paper_meta["score"], }