Browse Source

Use jsDelivr as cdn

pull/244/head
Jerome Wu 6 years ago
parent
commit
244a948991
  1. 8
      README.md
  2. 8
      src/browser/index.js
  3. 2
      src/node/index.js

8
README.md

@ -251,19 +251,19 @@ Because of this we recommend loading `tesseract.js` from a CDN. But if you reall
```javascript ```javascript
window.Tesseract = Tesseract.create({ window.Tesseract = Tesseract.create({
workerPath: '/path/to/worker.js', workerPath: '/path/to/worker.js',
langPath: 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/',
corePath: 'https://rawcdn.githack.com/naptha/tesseract.js-core/0.1.0/index.js', corePath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js',
}) })
``` ```
### corePath ### corePath
A string specifying the location of the [tesseract.js-core library](https://github.com/naptha/tesseract.js-core), with default value 'https://rawcdn.githack.com/naptha/tesseract.js-core/master/index.js'. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file. A string specifying the location of the [tesseract.js-core library](https://github.com/naptha/tesseract.js-core), with default value 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js'. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file.
### workerPath ### workerPath
A string specifying the location of the [worker.js](./dist/worker.js) file. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file. A string specifying the location of the [worker.js](./dist/worker.js) file. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use a different file.
### langPath ### langPath
A string specifying the location of the tesseract language files, with default value 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/'. Language file URLs are calculated according to the formula `langPath + langCode + '.traineddata.gz'`. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use different language files. A string specifying the location of the tesseract language files, with default value 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/'. Language file URLs are calculated according to the formula `langPath + langCode + '.traineddata.gz'`. Set this string before calling `Tesseract.recognize` and `Tesseract.detect` if you want Tesseract.js to use different language files.
## Contributing ## Contributing

8
src/browser/index.js

@ -1,7 +1,7 @@
var defaultOptions = { var defaultOptions = {
// workerPath: 'https://rawcdn.githack.com/naptha/tesseract.js/0.2.0/dist/worker.js', // workerPath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@0.2.0/dist/worker.js',
corePath: 'https://rawcdn.githack.com/naptha/tesseract.js-core/0.1.0/index.js', corePath: 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@0.1.0/index.js',
langPath: 'https://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/',
} }
if (process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === "development") {
@ -9,7 +9,7 @@ if (process.env.NODE_ENV === "development") {
defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js?nocache=' + Math.random().toString(36).slice(3) defaultOptions.workerPath = location.protocol + '//' + location.host + '/dist/worker.dev.js?nocache=' + Math.random().toString(36).slice(3)
}else{ }else{
var version = require('../../package.json').version; var version = require('../../package.json').version;
defaultOptions.workerPath = 'https://rawcdn.githack.com/naptha/tesseract.js/' + version + '/dist/worker.js' defaultOptions.workerPath = 'https://cdn.jsdelivr.net/gh/naptha/tesseract.js@' + version + '/dist/worker.js'
} }
exports.defaultOptions = defaultOptions; exports.defaultOptions = defaultOptions;

2
src/node/index.js

@ -5,7 +5,7 @@ const fetch = require('isomorphic-fetch'),
exports.defaultOptions = { exports.defaultOptions = {
workerPath: require('path').join(__dirname, 'worker.js'), workerPath: require('path').join(__dirname, 'worker.js'),
langPath: 'http://rawcdn.githack.com/naptha/tessdata/gh-pages/3.02/', langPath: 'https://cdn.jsdelivr.net/gh/naptha/tessdata@gh-pages/3.02/',
} }
exports.spawnWorker = function spawnWorker(instance, workerOptions){ exports.spawnWorker = function spawnWorker(instance, workerOptions){

Loading…
Cancel
Save