-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Added a custom Export for academicpages.github.io #14463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GreLucie
wants to merge
43
commits into
JabRef:main
Choose a base branch
from
GreLucie:fix-for-issue-12727
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+457
−0
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
48450d4
modification des fichiers qui font la configuration des exporters
sadok-lajmi 65bbc44
Adding the empty layouts in resources/resource/layout/academicpages
GreLucie a4e2fea
création du fichier academicpages.article.layout
sadok-lajmi 3e34b92
utilisation du fichier article.layout pour le new TemplateExporter
sadok-lajmi 8e76f57
generalisation du layout en utilisant academicpages.layout
sadok-lajmi 2799f1d
améliorations au academicpages layout
sadok-lajmi be96c94
ajout d'un custom formatter to help with academic layout
sadok-lajmi 1421e98
AcademicPagesExporter
GreLucie e4a987c
test: add AcademicPagesExporter tests
AloisHasNeurons df7aa05
Delete unecessary imports
GreLucie 9b12666
Changelog
GreLucie f588da4
Changed CHANGELOG.md
GreLucie de65527
trying to fix the CHANGELOG.md
GreLucie 2d8afcf
Adding blankspace in CHANGELOG.md
GreLucie 4ea372d
Correction du nouveau exporter + Cohérence des noms des fichiers prod…
sadok-lajmi 3972b34
Merge remote-tracking branch 'origin/fix-for-issue-12727' into fix-fo…
sadok-lajmi 9b8a86d
Reverted the date on the CHANGELOG.md and one change on AcademicPages…
GreLucie 9087390
revert all changes to Changelog.md
GreLucie 655afe3
format correction for the file : LayoutEntry
sadok-lajmi 4d7dac1
Merge remote-tracking branch 'origin/fix-for-issue-12727' into fix-fo…
sadok-lajmi 30e7626
trying to fix Open Rewrite problem
GreLucie 6e07a52
Refactor AcademicPagesExporterTest to use full content comparison
AloisHasNeurons 01f43cc
Merge branch 'fix-for-issue-12727' of https://github.com/GreLucie/jab…
AloisHasNeurons ad339be
Removed false import statement in tests.
AloisHasNeurons aaa5855
deleted useless import in AcademicPagesExporter.java
GreLucie 3547cd0
Merge branch 'fix-for-issue-12727' of https://github.com/GreLucie/jab…
GreLucie 7b55f27
correction of the error given by the localizationconsistancy test
sadok-lajmi ec19bb9
Merge branch 'main' into fix-for-issue-12727
sadok-lajmi 05792cb
Merge branch 'main' into fix-for-issue-12727
GreLucie 7ccbc6f
Updated CHANGELOG.md
GreLucie 6f25e5c
added the link to issue 12727
GreLucie 3c24b32
Update jablib/src/main/java/org/jabref/logic/exporter/AcademicPagesEx…
GreLucie b38bed2
Adressing some of the comments regarding the PR
GreLucie fe03fc4
Merge branch 'main' into fix-for-issue-12727
GreLucie c2a06e0
Comment added for replaceFormatter.setArgument(' ,-')
GreLucie 280a1fb
tests: added 4 test cases and specified the SaveException
AloisHasNeurons 6a4c5b0
Fixed submodules?
AloisHasNeurons 100fe95
add all formatters as class variable
Memeel 07088a8
changed a comment
GreLucie fcd3db4
Trying to fix indentation in AcademicPagesExporterTest
GreLucie 1efe4a2
Revert change on AcademicPagesExporter
GreLucie 488620d
Fixed some indentation in AcademicPagesExporterTest
GreLucie 5d6e3a2
add all formatters as class variable
Memeel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
jablib/src/main/java/org/jabref/logic/exporter/AcademicPagesExporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package org.jabref.logic.exporter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
| import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
| import org.jabref.logic.layout.LayoutFormatterPreferences; | ||
| import org.jabref.logic.layout.format.HTMLChars; | ||
| import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter; | ||
| import org.jabref.logic.layout.format.Replace; | ||
| import org.jabref.logic.layout.format.SafeFileName; | ||
| import org.jabref.logic.util.StandardFileType; | ||
| import org.jabref.logic.util.io.FileUtil; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.metadata.SelfContainedSaveOrder; | ||
|
|
||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| /** | ||
| * A custom exporter to write multiple bib entries as AcademicPages Markdown format. | ||
| */ | ||
| public class AcademicPagesExporter extends Exporter { | ||
| private final String layoutFileFileName; | ||
| private final String directory; | ||
| private final LayoutFormatterPreferences layoutPreferences; | ||
| private final SelfContainedSaveOrder saveOrder; | ||
|
|
||
| private final Replace replaceFormatter = new Replace(); | ||
| private final RemoveLatexCommandsFormatter commandsFormatter = new RemoveLatexCommandsFormatter(); | ||
| private final HTMLChars htmlFormatter = new HTMLChars(); | ||
| private final SafeFileName safeFormatter = new SafeFileName(); | ||
|
|
||
| private TemplateExporter academicPagesTemplate; | ||
|
|
||
| /** | ||
| * Initialize another export format based on templates stored in directory. | ||
| * | ||
| */ | ||
| public AcademicPagesExporter(LayoutFormatterPreferences layoutPreferences, SelfContainedSaveOrder saveOrder) { | ||
| super("academicpages", "academic pages markdowns", StandardFileType.MARKDOWN); | ||
| this.layoutFileFileName = "academicpages"; | ||
| this.directory = "academicpages"; | ||
| this.layoutPreferences = layoutPreferences; | ||
| this.saveOrder = saveOrder; | ||
| String consoleName = "academicpages"; | ||
| this.academicPagesTemplate = new TemplateExporter("academicpages", consoleName, layoutFileFileName, directory, StandardFileType.MARKDOWN, layoutPreferences, saveOrder); | ||
| } | ||
|
|
||
| @Override | ||
| public void export(@NonNull final BibDatabaseContext databaseContext, | ||
| @NonNull final Path exportDirectory, | ||
| @NonNull List<BibEntry> entries) throws SaveException { | ||
| export(databaseContext, exportDirectory, entries, List.of(), JournalAbbreviationLoader.loadBuiltInRepository()); | ||
| } | ||
|
|
||
| /** | ||
| * The method that performs the export of all entries by iterating on the entries. | ||
| * | ||
| * @param databaseContext the database to export from | ||
| * @param file the directory to write to | ||
| * @param entries a list containing all entries that should be exported | ||
| * @param abbreviationRepository the built-in repository | ||
| * @throws SaveException Exception thrown if saving goes wrong | ||
| */ | ||
| @Override | ||
| public void export(@NonNull final BibDatabaseContext databaseContext, | ||
| @NonNull final Path file, | ||
| @NonNull List<BibEntry> entries, | ||
| List<Path> fileDirForDataBase, | ||
| JournalAbbreviationRepository abbreviationRepository) throws SaveException { | ||
| if (entries.isEmpty()) { // Only export if entries exist | ||
| return; | ||
| } | ||
| try { | ||
| // convert what the ExportCommand gives as a file parameter to a directory | ||
| Path baseDir = file; | ||
| String exportDirectoryString = FileUtil.getBaseName(file); | ||
| Path exportDirectory = baseDir.getParent().resolve(exportDirectoryString); | ||
|
|
||
| // Ensure the directory exists. This is important: AtomicFileWriter will fail if parent dirs are missing. | ||
| Files.createDirectories(exportDirectory); | ||
|
|
||
| for (BibEntry entry : entries) { | ||
| // formatting the title of each entry to match the file names format demanded by academic pages (applying the same formatters applied to the title in the academicpages.layout) | ||
| Path path = getPath(entry, exportDirectory); | ||
|
|
||
| List<BibEntry> individualEntry = new ArrayList<>(); | ||
| individualEntry.add(entry); | ||
| academicPagesTemplate.export(databaseContext, path, individualEntry, fileDirForDataBase, abbreviationRepository); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new SaveException("could not export", e); | ||
| } | ||
| } | ||
|
|
||
| private @NonNull Path getPath(BibEntry entry, Path exportDirectory) { | ||
| replaceFormatter.setArgument(" ,-"); // expects an expression that has the character to remove and the replacement character separated by a comma. | ||
| String title = entry.getTitle().get(); | ||
| String formattedTitle = commandsFormatter.format(htmlFormatter.format(replaceFormatter.format(title))); | ||
| String safeTitle = safeFormatter.format(formattedTitle); | ||
| return exportDirectory.resolve(safeTitle + ".md"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
jablib/src/main/java/org/jabref/logic/layout/format/NumberMonthFormatter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.jabref.logic.layout.format; | ||
|
|
||
| import org.jabref.logic.layout.LayoutFormatter; | ||
| import org.jabref.model.entry.Month; | ||
|
|
||
| /** | ||
| * Convert the month name into the corresponding number and return 01 by default | ||
| */ | ||
| public class NumberMonthFormatter implements LayoutFormatter { | ||
|
|
||
| @Override | ||
| public String format(String fieldText) { | ||
| return Month.parse(fieldText).map(Month::getTwoDigitNumber).orElse("01"); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
jablib/src/main/java/org/jabref/logic/layout/format/SafeFileName.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.jabref.logic.layout.format; | ||
|
|
||
| import org.jabref.logic.layout.LayoutFormatter; | ||
|
|
||
| /** | ||
| * Remove all the characters that are not allowed by the OS in file names | ||
| */ | ||
| public class SafeFileName implements LayoutFormatter { | ||
|
|
||
| @Override | ||
| public String format(String fieldText) { | ||
| return fieldText.replaceAll("[\\\\/:*?\"<>|]", ""); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
jablib/src/main/resources/resource/layout/academicpages/academicpages.layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| title: "\format[RemoveLatexCommands,HTMLChars]{\title}" | ||
| collection: publications | ||
| category: \format{\entrytype} | ||
| permalink: /publication/\format[RemoveLatexCommands,HTMLChars,Replace(\s,-),SafeFileName]{\title} | ||
| excerpt: '\begin{note}\format[RemoveLatexCommands,HTMLChars]{\note}\end{note}' | ||
| date: \format{\year}-\begin{month}\format[NumberMonth]{\month}\end{month}\begin{!month}01\end{!month}-\begin{day}\format{\day}\end{day}\begin{!day}01\end{!day} | ||
| venue: '\format[RemoveLatexCommands,HTMLChars]{\journal}\begin{!journal}Unknown\end{!journal}' | ||
| slidesurl: '\begin{file}\format[FileLink(pdf)]{\file}\end{file}\begin{!file}https://[insert username].github.io/files/[insert filename].pdf\end{!file}' | ||
| paperurl: '\begin{file}\format[FileLink(pdf)]{\file}\end{file}\begin{!file}https://[insert username].github.io/files/[insert filename].pdf\end{!file}' | ||
| bibtexurl: 'https://[insert username].github.io/files/[insert filename].bib' | ||
| citation: '\format[HTMLChars]{\author}. (\format{\year}). ""\format[RemoveLatexCommands,HTMLChars]{\title}." <i>\format[RemoveLatexCommands,HTMLChars]{\journal}</i>.' | ||
| --- | ||
| \begin{abstract}\format{\abstract}\end{abstract} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simply switch this to a normal for loop with for (int i =1; i< entiries.length; i++) so you don't need the iterator variable.