clarin-dspace icon indicating copy to clipboard operation
clarin-dspace copied to clipboard

Implement custom format template interpolation for refbox citation display

Open Copilot opened this issue 4 months ago • 5 comments

This PR implements support for custom format templates in the refbox citation display, allowing users to define their own citation formats through metadata while maintaining backward compatibility.

Problem

The refbox display text was using a hardcoded format that couldn't be customized per item. Users needed the ability to define custom citation formats using metadata fields.

Solution

Modified the ClarinRefBoxController to support a new local.refbox.format metadata field that acts as a template string with variable interpolation:

  • Template support: When local.refbox.format metadata exists, it's used as a format template with variable substitution
  • Variable interpolation: Supports {title}, {authors}, {pid}, {repository}, {year}, and {publisher} variables
  • Backward compatibility: When no custom format is present, uses the existing hardcoded format behavior
  • Flexible formatting: Users can now create custom citation formats like "{authors} ({year}). {title}. {publisher}. {repository}. {pid}"

Example Usage

Items with local.refbox.format metadata will use the custom template:

Metadata: local.refbox.format = "{authors}: {title} [{year}]"
Output: "John Doe: Sample Article [2024]"

Items without the metadata field will continue using the default format for backward compatibility.

Testing

Added comprehensive test cases covering:

  • Custom format templates with all variables
  • Partial variable usage in templates
  • Default behavior when no template is present

Fixes #1229


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Aug 08 '25 12:08 Copilot

@kosarko 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot avatar Aug 08 '25 12:08 Copilot

@copilot the pull request should have been against the clarin-v7 branch. This branch contains the instructions. I have changed the PR merge base and I have forced push to copilot/fix-1229 to update this branch to clarin-v7. I've included your initial plan commit. Can you start again?

kosarko avatar Aug 08 '25 12:08 kosarko

@copilot the pull request should have been against the clarin-v7 branch. This branch contains the instructions. I have changed the PR merge base and I have forced push to copilot/fix-1229 to update th...

I've fixed the refbox format interpolation issue. The problem was that when both authors and publisher existed, the publisher field was being ignored. Now the display text properly includes both fields separately.

Changes made in commit e385bb2:

  • Modified buildDisplayText() method to extract publisher as a separate field
  • Updated format to include publisher when both authors and publisher exist
  • Maintained backward compatibility (publisher still acts as author fallback when no authors exist)
  • Added comprehensive test case to verify the fix

The refbox format now correctly displays: {authors}, {year}, {title}, {publisher}, {repository}, {identifier} instead of missing the dc.publisher field.

Copilot avatar Aug 08 '25 13:08 Copilot

@copilot I see that the issue description was too vague. You seem to have found the correct files to modify, but the intention was:

if there is a local.refbox.format metadata field, this field will contain something like a python fstring (string with variable names in curly braces such as {title}). This should be used rather than the hardcoded format/order currently implemented in buildDisplayText. The variables in the format string need to be interpolated. Possible variables are: title, authors, pid, repository, year, and publisher.

when local.refbox.format is not present the buildDisplayText should behave as it does now.

kosarko avatar Aug 08 '25 13:08 kosarko

@copilot I see that the issue description was too vague. You seem to have found the correct files to modify, but the intention was:

if there is a local.refbox.format metadata field, this field wi...

I've implemented the custom format template functionality as requested. The solution now checks for a local.refbox.format metadata field and uses it for string interpolation when present, falling back to the default hardcoded format when absent.

Changes made in commit upcoming:

  • Modified buildDisplayText() to check for local.refbox.format metadata
  • Added buildDisplayTextFromTemplate() method for variable interpolation with support for: {title}, {authors}, {pid}, {repository}, {year}, {publisher}
  • Refactored existing logic into buildDisplayTextDefault() to maintain backward compatibility
  • Added comprehensive test cases to verify both template and default behavior

The implementation supports all requested variables and maintains full backward compatibility when no template is provided.

Copilot avatar Aug 08 '25 13:08 Copilot