repeat-space / anki-apkg-export Goto Github PK
View Code? Open in Web Editor NEW:book: Generate decks for Anki (spaced repetition software)
:book: Generate decks for Anki (spaced repetition software)
I was eyeballing the code and it does not look like subdecks are supported? If that's right is there any plans on adding that? I have two websites[0][1] which uses this cool project and I was hoping to add support for subdecks.
Thanks.
[0]: http://notion2anki.alemayhu.com/
[1]: https://workflowy2anki.alemayhu.com/
Hello,
I attempted to use anki-apkg-export
to generate 861 cards, but am reaching the memory limit before they are all added.
The final apkg file is 87KB so I don't know why I am hitting the current ~18MB limit that sql.js
has. Regardless, I am wondering if I would be able to either:
have anki-apkg-export
use a custom sql.js
that is compiled to have a TOTAL_MEMORY
of 512MB
have anki-apkg-export
use sql-memory-growth.js
instead of sql.js
without modifying the dist/index.js
file directly
Enlarging the arrays adds overhead that doubles the execution time when compared to increasing the TOTAL_MEMORY
, so I would prefer the first option.
I am new to nodejs so perhaps I am off-topic and this is possible with yarn scripts.
Thanks,
David
I tried to fix the issue #18 by checking if window object is present.
I added
|| typeof window !== 'undefined'
here: https://github.com/ewnd9/anki-apkg-export/blob/master/src/index.js#L8
and here: https://github.com/ewnd9/anki-apkg-export/blob/master/src/exporter.js#L56
(but in dist folder) and it worked. But I faced an error:
Unfortunately, I don't understand the cause of the error. script
and raw
loaders are installed. Maybe the reason is in webpack config somewhere, but can't edit it.
Do you have an idea what can cause this error and how I could fix it?
In case you'd like to try it yourself, I created a minimal representation of this case in this repo:
https://github.com/yakhinvadim/anki-apkg-export-error
This is app, created with create-react-app. My changes for this case are in this commit yakhinvadim/anki-apkg-export-error@4fec6c2
I have done following steps to create bundle.js but getting following error.
1. Forked the GitHub
2. Change to directory
anki-apkg-export-master/examples/browser
3. npm install
4. npm run build
Getting error
ERROR in Cannot find module babel-core
Installed npm install babel-core
5. Again,
Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3"
Then npm install babel-loader@next
6. Then npm run build
ERROR in ./index.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-preset-es2015\lib\index.js
at createDescriptor (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-descriptors.js:178:11)
at C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-descriptors.js:109:50
at Array.map (<anonymous>)
at createDescriptors (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
at presets (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-descriptors.js:47:19)
at mergeChainOpts (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-chain.js:384:26)
at C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-chain.js:347:7
at Generator.next (<anonymous>)
at buildRootChain (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\config-chain.js:129:29)
at buildRootChain.next (<anonymous>)
at loadPrivatePartialConfig (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\partial.js:99:62)
at loadPrivatePartialConfig.next (<anonymous>)
at Function.<anonymous> (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\partial.js:125:25)
at Generator.next (<anonymous>)
at evaluateSync (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\gensync\index.js:244:28)
at Function.sync (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\gensync\index.js:84:14)
at Object.<anonymous> (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\node_modules\@babel\core\lib\config\index.js:43:61)
at Object.<anonymous> (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:82:26)
at Generator.next (<anonymous>)
at step (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:3:221)
at _next (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:3:409)
at C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:3:477
at new Promise (<anonymous>)
at Object.<anonymous> (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:3:97)
at Object._loader (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:148:18)
at Object.loader (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:36:18)
at Object.<anonymous> (C:\Users\manik\Desktop\anki-apkg-export-master\anki-apkg-export-master\examples\browser\node_modules\babel-loader\lib\index.js:31:12)
What will be implementation to resolve issues? Or have I done any mistake in installing?
Test hhzl@8397a6d has an example of importing cards with tags.
The tags are imported and show up in the Anki browser when the whole collection is selected. (Anki version 2.0.38 on Linux)
.
However then selecting a tag in the browser no entries are shown
.
If create a new user in Anki 2.0.38 and import the CSV file the tags are fine.
It might be an issue with space in the tags field.
The case which does not work
sqlite> select tags,flds,sfld from notes order by tags,sfld;
animal|cock�der Hahn|cock
animal|cow�die Kuh|cow
animal|dog�der Hund|dog
animal|goat�die Ziege|goat
animal|hen�das Henne|hen
animal|hyena�die Hyäne|hyena
animal|lion�der Löwe|lion
food|flour�das Mehl|flour
food|oil�das Öl|oil
food|rice�der Reis|rice
food|salt�das Salz|salt
food|water�das Wasser|water
food fruit|banana�die Banane|banana
food fruit|lemon�die Zitrone|lemon
food fruit|pear�die Birne|pear
food vegetable|carrot�die Karotte|carrot
food vegetable|onion�die Zwiebel|onion
food vegetable|tomato�die Tomate|tomato
nature|a river�ein Fluss|a river
nature|a tree�ein Baum|a tree
nature sky|one star�ein Stern|one star
nature sky|the moon�der Mond|the moon
nature sky|the sun�die Sonne|the sun
nature sky|three stars�drei Sterne|three stars
nature sky|two stars�zwei Sterne|two stars
sqlite>
The case which works fine in the browser
sqlite> select tags,flds,sfld from notes order by tags,sfld;
animal |cock�der Hahn|cock
animal |cow�die Kuh|cow
animal |dog�der Hund|dog
animal |goat�die Ziege|goat
animal |hen�das Henne|hen
animal |hyena�die Hyäne|hyena
animal |lion�der Löwe|lion
food |flour�das Mehl|flour
food |oil�das Öl|oil
food |rice�der Reis|rice
food |salt�das Salz|salt
food |water�das Wasser|water
food fruit |banana�die Banane|banana
food fruit |lemon�die Zitrone|lemon
food fruit |pear�die Birne|pear
food vegetable |carrot�die Karotte|carrot
food vegetable |onion�die Zwiebel|onion
food vegetable |tomato�die Tomate|tomato
nature |a river�ein Fluss|a river
nature |a tree�ein Baum|a tree
nature sky |one star�ein Stern|one star
nature sky |the moon�der Mond|the moon
nature sky |the sun�die Sonne|the sun
nature sky |three stars�drei Sterne|three stars
nature sky |two stars�zwei Sterne|two stars
sqlite>
More tests needed to come up with a fix....
The next test will be to manually add a space after the tags field with an update
statement and check if this solves the problem.
When learning language, answer template would be more convenient if it would look something like {{Front}}<hr>{{Back}}
instead of just showing the back card. Thus would be nice to have control over the question and answer templates.
Would be nice if we could add images and sounds files into deck cards.
If you support this feature, I can help to implement :-)
const fs = require('fs');
const AnkiExport = require('anki-apkg-export').default;
const apkg = new AnkiExport('deck-name');
apkg.addMedia('picture.jpg', fs.readFileSync('/tmp/picture.jpg'));
apkg.addCard('card #1 front <img src="picture.jpg"/ >', 'card #1 back');
apkg.addCard('card #2 front', 'card #2 back');
const zip = apkg.save();
fs.writeFileSync('./output.apkg', zip, 'binary');
console.log(`Package has been generated: output.pkg`);
Hi. Can you share info about full anki card format? It there any information about adding media into cards ?
I'm interesting how you see adding tags in existing api ? Special format for text files, or use directory name as tags ( like some/sub/dir1/file.txt
=> tags ['some', 'sub', 'dir1']
)
Hi, it's me again :)
After last changes, everything works great, thanks! Apkg file is generated and successfully imported by Anki.
But cards' back side doesn't look as expected.
I looked into anki manual and found this: (https://apps.ankiweb.net/docs/manual.html#basic-templates)
The default back template will look something like this:
{{FrontSide}}
<hr id=answer>
{{Back}}
But cards, generated by anki-apkg-export, has this template:
{{Back}}
Deck templates could be changed in anki settings, but I don't think users should do it manually.
IMO, it would be more convenient for users, if generated decks had default templates. Here's an example of what it looks like:
What do you think?
I'm trying export deck with 841 cards and get
Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0
Is there any way to work with deck in pipe-style? or the only solution - increase limit ?
It is actually the port of https://github.com/albertzak/anki2 Apparently I had two open tabs at the time of writing docs
@ewnd9 I realise this library is an almost identical port of the existing Ruby library. It gets the essential use case of building anki decks correct, simple and easy. You've achieved that well, thanks for everyone's work 🏆
My questions are around future of this project.
I ask this because I want to customise more aspects of the generated decks. Some features/ideas I have, and am happy to help with, are:
notes
api, e.g addNote
addCard
from creating both a note
and a card
If this not the direction you envision the library heading in, that's ok 😄. I can look into implementing these in another way 👌
I have used browserify to make npm package available in browser.
index.js
var AnkiExporter = require('anki-apkg-export/dist/exporter');
global.window.AnkiExporter = AnkiExporter;
Then,
browserify index.js -o export.js
Using export.js
with this example, give following errors.
<html>
<body>
<script src="fs.js"></script>
<script src="export.js"></script>
<script>
var apkg = new AnkiExport('deck-name');
apkg.addCard('card #1 front', 'card #1 back');
apkg.addCard('card #2 front', 'card #2 back', { tags: ['nice', 'better card'] });
apkg.addCard('card #3 with image <img src="anki.png" />', 'card #3 back');
apkg
.save()
.then(zip => {
fs.writeFileSync('./output.apkg', zip, 'binary');
console.log(`Package has been generated: output.pkg`);
})
.catch(err => console.log(err.stack || err));
</script>
</body>
</html>
What I am missing here? Tried other approach also.
I'm using anki-apkg-export to generate an .apkg-file from a google docs document. The idea is to regenerate the .apkg-file and re-import it whenever "cards" have been updated/added in the google docs-document. As it is now all cards, even those that are completely identical will be imported as duplicates (→ makes it hard to keep scheduling info etc). Is there a way to avoid the duplicate problem?
Hi!
Thank you for this project. I'd like to use it in my web app longman-to-anki to generate anki deck on client side. Unfortunately, my stack doesn't allow me to pass APP_ENV to my app.
I'm using create-react-app, where all build scripts are hidden, so I don't have access to webpack config.
Create-react-app allows to use environment variables, but only as long, as their name starts with REACT_APP_ (more about it here), so I can't create variable APP_ENV.
Is there any way environment could be inferred without passing environment variable?
Maybe, by checking if there is window
object presented? If yes, I'd be glad to send a PR.
If no, do you see any way I can pass it to my project? Maybe I'm missing something.
@ewnd9 What about removing random generation / new Date during work? It makes harder to compare values and give no pros. We can just have incremented counter for each deck
Then we'll be able to compare decks with pre-generated in binary. And we'll be able to use sorting by id on queries
P.S. just note - why export
when class import data into Anki deck?
I get this error when I try to run the lib in Docker (image: lts-slim
)
How to reproduce
require('anki-apkg-export').default
What I expected
I realized that the dist/index.js
at line 23 tries to use script-loader
if window
is not undefined or the APP_ENV
is browser. Neither should be true in my case as I'm running this on the server. I logged the value of window
in Docker and for some reason its object
and NOT undefined
.
I'm not sure what is the correct solution here. Can someone help please?
Hello and thanks for this nice library.
I am a beginner in node NPM, webpack etc..... I read your documentation but really struggle to understand how to install and run your library. I am really confused on how to install the different dependencies and how to do the call to all of these scripts from my webpage.
I simply want to reproduice on my website the sample application of https://ewnd9.com/anki-apkg-export-app/.
Could you please add a little bit more information about the required steps to install/configure the required tools and libraries?
It would help a lot, thanks!
Hey, @ewnd9!
How do you feel about updating dependencies for this project? I'd be glad to do it myself and make a PR if you're busy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.