项目作者: repeat-space

项目描述 :
:book: Generate decks for Anki (spaced repetition software)
高级语言: JavaScript
项目地址: git://github.com/repeat-space/anki-apkg-export.git
创建时间: 2016-03-31T03:47:50Z
项目社区:https://github.com/repeat-space/anki-apkg-export

开源协议:

下载


anki-apkg-export

Build Status

Universal module for generating decks for Anki.

Port of the Ruby gem https://github.com/albertzak/anki2

Install

  1. $ npm install anki-apkg-export --save

Usage

server

  1. const fs = require('fs');
  2. const AnkiExport = require('anki-apkg-export').default;
  3. const apkg = new AnkiExport('deck-name');
  4. apkg.addMedia('anki.png', fs.readFileSync('anki.png'));
  5. apkg.addCard('card #1 front', 'card #1 back');
  6. apkg.addCard('card #2 front', 'card #2 back', { tags: ['nice', 'better card'] });
  7. apkg.addCard('card #3 with image <img src="anki.png" />', 'card #3 back');
  8. apkg
  9. .save()
  10. .then(zip => {
  11. fs.writeFileSync('./output.apkg', zip, 'binary');
  12. console.log(`Package has been generated: output.pkg`);
  13. })
  14. .catch(err => console.log(err.stack || err));

browser

Intended to be used with webpack

  1. const webpack = require('webpack');
  2. module.exports = {
  3. entry: './index.js',
  4. module: {
  5. loaders: [
  6. {
  7. test: /\.js$/,
  8. exclude: /node_modules/,
  9. loader: 'babel'
  10. },
  11. ]
  12. },
  13. plugins: [
  14. new webpack.DefinePlugin({
  15. 'process.env': {
  16. NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
  17. },
  18. })
  19. ],
  20. output: {
  21. path: __dirname,
  22. filename: 'bundle.js'
  23. }
  24. };

Required loaders:

  1. import { saveAs } from 'file-saver';
  2. import AnkiExport from 'anki-apkg-export';
  3. const apkg = new AnkiExport('deck-name');
  4. // could be a File from <input /> or a Blob from fetch
  5. // take a look at the example folder for a complete overview
  6. apkg.addMedia('anki.png', file);
  7. apkg.addCard('card #1 front', 'card #1 back');
  8. apkg.addCard('card #2 front', 'card #2 back', { tags: ['nice', 'better card'] });
  9. apkg.addCard('card #3 with image <img src="anki.png" />', 'card #3 back');
  10. apkg
  11. .save()
  12. .then(zip => {
  13. saveAs(zip, 'output.apkg');
  14. })
  15. .catch(err => console.log(err.stack || err));

Examples

Changelog

  • v4.0.0 - expose template variables (frontside, backside and css)
  • v3.1.0 - make setting APP_ENV optional
  • v3.0.0 - add tags, ES6 refactor (breaking)
  • v2.0.0 - add media support, update jszip dependency (breaking)
  • v1.0.0 - initial rewrite

Tips

  • issue#25 - Dealing with sql.js memory limits

License

MIT © ewnd9