-
Notifications
You must be signed in to change notification settings - Fork 28
Glossary generator with apa lookup #595
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f6757ef
Add bibtex apa json generator
kaysiz df39d64
Initial apa look up file
kaysiz f3eb0a5
refactor translation markdown generation code
kaysiz 6f711b3
update workflow to add new flow to generate glossary
kaysiz 266adb2
Merge branch 'master' into ks-refactor-glossary-generator
kaysiz 5c291b3
Address review comments
kaysiz dc80c3c
Update gitignore
kaysiz 43aef0c
Merge branch 'ks-refactor-glossary-generator' of github.com:forrtproj…
kaysiz 90edaf1
Merge branch 'master' into ks-refactor-glossary-generator
kaysiz fded9da
Implement missing reference tracking
kaysiz a5a4029
Merge branch 'master' into ks-refactor-glossary-generator
kaysiz 53bade3
Update .github/workflows/data-processing.yml
kaysiz a1c329c
Merge branch 'master' into ks-refactor-glossary-generator
kaysiz 48953e8
Remove duplicate cache-dependency-path entry
kaysiz 4c691a4
Merge branch 'master' into ks-refactor-glossary-generator
LukasWallrich ca7349a
fix references and associated languages
kaysiz 4e0fe79
Merge branch 'master' into ks-refactor-glossary-generator
kaysiz 90cb63c
Update bibtex_to_apa/package.json
kaysiz a0f1e5b
display references as list
kaysiz 1e81d6f
fix merge error with workflow
kaysiz 299d50f
Update content/glossary/_create_glossaries.py
kaysiz 6345e14
Update bibtex_to_apa/bibtex_to_apa.js
kaysiz 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| const { Cite } = require('@citation-js/core'); | ||
| require('@citation-js/plugin-bibtex'); | ||
| require('@citation-js/plugin-csl'); | ||
| const fs = require('fs'); | ||
|
|
||
| const DEFAULT_INPUT = 'https://docs.google.com/document/d/1-KKsOYZWJ3LdgdO2b2uJsOG2AmUDaQBNqWVVTY2W4W8/edit?tab=t.0'; | ||
| const DEFAULT_OUTPUT = 'apa_lookup.json'; | ||
|
|
||
| async function fetchBibtex(input) { | ||
| if (!input.startsWith('http')) { | ||
| return fs.readFileSync(input, 'utf-8'); | ||
kaysiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (input.includes('docs.google.com')) { | ||
| const match = input.match(/\/d\/([a-zA-Z0-9_-]+)/); | ||
| if (!match) throw new Error('Invalid Google Doc URL'); | ||
| const exportUrl = `https://docs.google.com/document/d/${match[1]}/export?format=txt`; | ||
| const response = await fetch(exportUrl); | ||
| if (!response.ok) throw new Error(`Failed to fetch: ${response.status}`); | ||
| let text = await response.text(); | ||
| return text.replace(/\[[a-z]+\]/gi, ''); // Remove Google Docs comment markers | ||
| } | ||
kaysiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const response = await fetch(input); | ||
| if (!response.ok) throw new Error(`Failed to fetch: ${response.status}`); | ||
| return response.text(); | ||
| } | ||
|
|
||
| function extractUrl(entry) { | ||
| if (entry.URL) return entry.URL; | ||
| if (entry.note) { | ||
| const match = entry.note.match(/https?:\/\/[^\s]+/); | ||
| if (match) return match[0]; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function bibtexToApaJson(bibtexContent, includeUrl = true) { | ||
| const cite = new Cite(bibtexContent); | ||
| const result = {}; | ||
|
|
||
| for (const entry of cite.data) { | ||
| const key = entry.id || entry['citation-key']; | ||
| let ref = new Cite(entry).format('bibliography', { | ||
| format: 'text', | ||
| template: 'apa', | ||
| lang: 'en-US' | ||
| }).trim(); | ||
|
|
||
| if (includeUrl) { | ||
| const url = extractUrl(entry); | ||
| if (url && !url.includes('doi.org') && !ref.includes(url)) { | ||
| ref = ref.match(/https?:\/\/[^\s]+$/) | ||
| ? `${ref} Retrieved from ${url}` | ||
| : ref.replace(/\.?$/, `. Retrieved from ${url}`); | ||
| } | ||
| } | ||
|
|
||
| result[key] = ref; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
kaysiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async function main() { | ||
| const args = process.argv.slice(2); | ||
| let input = DEFAULT_INPUT; | ||
| let output = DEFAULT_OUTPUT; | ||
| let includeUrl = true; | ||
|
|
||
| for (let i = 0; i < args.length; i++) { | ||
| if (args[i] === '-i' || args[i] === '--input') input = args[++i]; | ||
| else if (args[i] === '-o' || args[i] === '--output') output = args[++i]; | ||
| else if (args[i] === '--no-url') includeUrl = false; | ||
| else if (args[i] === '-h' || args[i] === '--help') { | ||
| console.log( | ||
| `Usage: node bibtex_to_apa.js [-i INPUT] [-o OUTPUT] [--no-url] | ||
| Options: | ||
| -i, --input Input BibTeX (URL or file). Default: Google Doc | ||
| -o, --output Output JSON file. Default: apa_lookup.json | ||
| --no-url Don't append URLs to references` | ||
| ); | ||
| process.exit(0); | ||
| } | ||
| } | ||
|
|
||
| const bibtex = await fetchBibtex(input); | ||
| const apaJson = bibtexToApaJson(bibtex, includeUrl); | ||
| fs.writeFileSync(output, JSON.stringify(apaJson, null, 2)); | ||
| console.log(`Wrote ${Object.keys(apaJson).length} references to ${output}`); | ||
| } | ||
|
|
||
| main().catch(console.error); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Uh oh!
There was an error while loading. Please reload this page.