├── .gitignore ├── .tool-versions ├── Capfile ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── application.js │ │ ├── download.coffee │ │ ├── juans.coffee │ │ └── static_pages.coffee │ └── stylesheets │ │ ├── application.scss │ │ ├── download.scss │ │ └── juans.scss ├── controllers │ ├── application_controller.rb │ ├── canons_controller.rb │ ├── catalog_entry_controller.rb │ ├── chinese_tools_controller.rb │ ├── concerns │ │ ├── .keep │ │ └── cbeta_string.rb │ ├── download_controller.rb │ ├── export_controller.rb │ ├── juans_controller.rb │ ├── kwic3_controller.rb │ ├── lines_controller.rb │ ├── report_controller.rb │ ├── search_controller.rb │ ├── static_pages_controller.rb │ ├── textref_controller.rb │ ├── toc_node_controller.rb │ ├── word_seg_controller.rb │ └── works_controller.rb ├── errors │ └── cbeta_error.rb ├── helpers │ ├── application_helper.rb │ ├── download_helper.rb │ ├── export_helper.rb │ ├── juans_helper.rb │ ├── lines_helper.rb │ ├── sphinx_helper.rb │ ├── static_pages_helper.rb │ ├── toc_node_helper.rb │ └── works_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── README.md │ ├── analytics_record.rb │ ├── application_record.rb │ ├── canon.rb │ ├── catalog_entry.rb │ ├── category.rb │ ├── concerns │ │ └── .keep │ ├── gaiji.rb │ ├── goto_abbr.rb │ ├── juan_line.rb │ ├── lb_map.rb │ ├── line.rb │ ├── person.rb │ ├── place.rb │ ├── term.rb │ ├── toc_node.rb │ ├── variant.rb │ ├── visit.rb │ ├── work.rb │ └── xml_file.rb ├── services │ ├── authority_service.rb │ ├── crf.rb │ ├── int_to_zht.rb │ ├── kwic_service.rb │ ├── manticore_service.rb │ ├── matrix.rb │ ├── smith_waterman.rb │ ├── suffix_info.rb │ ├── unicode_service.rb │ └── word_seg_service.rb └── views │ ├── juans │ └── index.html.erb │ ├── layouts │ ├── _navbar_catalog.html.haml │ ├── _sidebar.haml │ └── application.html.erb │ ├── report │ ├── _datepicker.haml │ ├── daily.haml │ ├── index.haml │ ├── referer.haml │ └── url.haml │ ├── static_pages │ ├── _arg-cache.haml │ ├── _catalog-return.haml │ ├── _goto-linehead.haml │ ├── _html-for-ui-byline.haml │ ├── _html-for-ui-classes.haml │ ├── _html-for-ui-copyright.haml │ ├── _html-for-ui-facsimile.haml │ ├── _html-for-ui-gaiji.haml │ ├── _html-for-ui-graphic.haml │ ├── _html-for-ui-head.haml │ ├── _html-for-ui-juan.haml │ ├── _html-for-ui-lg.haml │ ├── _html-for-ui-linehead.haml │ ├── _html-for-ui-link.haml │ ├── _html-for-ui-note.haml │ ├── _html-for-ui-p.haml │ ├── _html-for-ui-person.haml │ ├── _html-for-ui-place.haml │ ├── _html-for-ui-punc.haml │ ├── _html-for-ui-table.haml │ ├── _html-for-ui-text.haml │ ├── _search-aio-q.haml │ ├── _search-aio-return.haml │ ├── _search-arg-paginate.haml │ ├── _sphinx-aio-q.haml │ ├── _sphinx-aio-return.haml │ ├── callback.html.erb │ ├── catalog.html.haml │ ├── catalog_index.haml │ ├── categories.html.haml │ ├── category.haml │ ├── chinese_tools.haml │ ├── common_parameters.haml │ ├── creators.html.haml │ ├── download.haml │ ├── download_docusky.haml │ ├── download_ebooks.haml │ ├── download_footnotes.haml │ ├── download_html.haml │ ├── download_text.haml │ ├── editions.html.haml │ ├── export.haml │ ├── get_html.html.haml │ ├── goto.html.haml │ ├── home.haml │ ├── html_for_ui.haml │ ├── line.html.haml │ ├── log.haml │ ├── log_old.html.haml │ ├── report.haml │ ├── rise_shine.haml │ ├── sc2tc.haml │ ├── scope_selector.haml │ ├── search.haml │ ├── search_all_in_one.haml │ ├── search_extended.haml │ ├── search_facet.haml │ ├── search_filter.haml │ ├── search_index.haml │ ├── search_kwic.haml │ ├── search_notes.haml │ ├── search_sc.haml │ ├── search_similar.haml │ ├── search_synonym.haml │ ├── search_title.haml │ ├── search_toc.html.haml │ ├── search_vars.haml │ ├── time.html.haml │ ├── toc.html.haml │ ├── word_count.html.haml │ ├── word_seg.html.haml │ ├── work.html.haml │ ├── work_index.haml │ └── works.html.haml │ ├── textref │ └── meta.csv │ └── word_seg │ └── index.haml ├── bin ├── bundle ├── rails ├── rake ├── setup ├── spring └── update ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── category-id.json ├── credentials.yml.enc ├── credentials │ └── cn.yml.enc ├── deploy.rb ├── deploy │ ├── cn.rb │ ├── production.rb │ ├── sakya.rb │ └── staging.rb ├── environment.rb ├── environments │ ├── cn.rb │ ├── development.rb │ ├── production.rb │ ├── staging.rb │ └── test.rb ├── initializers │ ├── application_controller_renderer.rb │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── content_security_policy.rb │ ├── cookies_serializer.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── new_framework_defaults.rb │ ├── permissions_policy.rb │ ├── rswag_ui.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── spring.rb └── storage.yml ├── data-static ├── categories.json ├── dynasty-order.csv ├── facsimile │ └── JM.json ├── layers │ └── fosizhi │ │ ├── GA │ │ ├── GA009 │ │ │ └── GA009n0008.csv │ │ ├── GA010 │ │ │ └── GA010n0009.csv │ │ ├── GA011 │ │ │ └── GA011n0010.csv │ │ ├── GA012 │ │ │ ├── GA012n0010.csv │ │ │ └── GA012n0011.csv │ │ ├── GA020 │ │ │ └── GA020n0017.csv │ │ ├── GA031 │ │ │ └── GA031n0032.csv │ │ ├── GA032 │ │ │ └── GA032n0032.csv │ │ ├── GA043 │ │ │ └── GA043n0043.csv │ │ ├── GA045 │ │ │ └── GA045n0049.csv │ │ ├── GA058 │ │ │ └── GA058n0062.csv │ │ ├── GA072 │ │ │ └── GA072n0077.csv │ │ ├── GA079 │ │ │ └── GA079n0081.csv │ │ ├── GA081 │ │ │ └── GA081n0084.csv │ │ ├── GA082 │ │ │ └── GA082n0084.csv │ │ ├── GA084 │ │ │ └── GA084n0086.csv │ │ ├── GA088 │ │ │ └── GA088n0089.csv │ │ ├── GA089 │ │ │ └── GA089n0089.csv │ │ └── GA090 │ │ │ └── GA090n0089.csv │ │ └── GB │ │ └── GB078 │ │ └── GB078n0109.csv ├── schema │ └── xml4docx.rnc ├── synonym.txt └── uuid │ ├── canons.json │ ├── juans.json │ └── works.json ├── db ├── analytics_migrate │ ├── 20201110030553_create_visits.rb │ └── 20220923035010_add_referer_to_visits.rb ├── analytics_schema.rb ├── migrate │ ├── 20190528080916_create_all.rb │ ├── 20211215083341_add_lb_end_to_juanlines.rb │ ├── 20221205031807_create_places.rb │ ├── 20230218080626_add_sort_to_catalog_entries.rb │ ├── 20230607054229_add_service_name_to_active_storage_blobs.active_storage.rb │ ├── 20230607054230_create_active_storage_variant_records.active_storage.rb │ ├── 20240222014726_add_vol_to_lines.rb │ ├── 20240318074051_add_pua_to_gaijis.rb │ └── 20241112055713_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb ├── schema.rb └── seeds.rb ├── doc ├── Quarterly.md ├── README.md ├── apache2.md ├── cbeta-change-log.md ├── cbeta-xml-p5a.md ├── cn.md ├── convert-for-download.md ├── deploy-rails-project.md ├── dev-mac.md ├── docx.md ├── ebook.md ├── https.md ├── import-layers.md ├── juan-line.md ├── kwic.md ├── mirror.md ├── new-rails-project.md ├── new-works.md ├── nginx.md ├── postgresql.md ├── prepare-files.md ├── rails.md ├── rdb.md ├── remove-old.md ├── rvm.md ├── server-setup.md ├── setup.md ├── sphinx-build-index.md ├── sphinx-mac.md ├── sphinx.md ├── sphinx3-ubuntu20.md ├── staging.md ├── trouble-shooting.md ├── update-github.md ├── uuid.md └── variants.md ├── lib ├── assets │ └── .keep └── tasks │ ├── .keep │ ├── README.md │ ├── cbeta-module.rb │ ├── cbeta_p5a_share.rb │ ├── check.rake │ ├── check_authority.rb │ ├── check_covers.rb │ ├── check_gaiji.rb │ ├── check_metadata.rb │ ├── convert.rake │ ├── convert_docusky.rb │ ├── convert_seg.rb │ ├── convert_toc.rb │ ├── convert_x2h.rb │ ├── convert_x2h_for_download.rb │ ├── convert_x2t4d2.rb │ ├── convert_x2t_for_download.rb │ ├── convert_xml4docx.rb │ ├── create.rake │ ├── create_creators.rb │ ├── create_uuid.rb │ ├── css_parser.rb │ ├── custom.rake │ ├── download.rake │ ├── download_ebooks.rb │ ├── export.rake │ ├── export_visits.rb │ ├── html-node.rb │ ├── import.rake │ ├── import_canons.rb │ ├── import_catalog.rb │ ├── import_category.rb │ ├── import_gaiji.rb │ ├── import_goto_abbrs.rb │ ├── import_jinglu_editors.rb │ ├── import_juan_line.rb │ ├── import_layers.rb │ ├── import_lb_maps.rb │ ├── import_lines-multi-edition.rb │ ├── import_lines.rb │ ├── import_synonym.rb │ ├── import_toc.rb │ ├── import_vars.rb │ ├── import_visits.rb │ ├── import_work_info.rb │ ├── kwic-builder.rb │ ├── kwic-h2t.rb │ ├── kwic-rotate.rb │ ├── kwic-sa.rb │ ├── kwic-sort-info.rb │ ├── kwic-test.rb │ ├── kwic-x2h.rb │ ├── kwic.rake │ ├── layers-ignore.txt │ ├── manticore-chunks.rb │ ├── manticore-notes.rb │ ├── manticore-t2x.rb │ ├── manticore-titles.rb │ ├── manticore.rake │ ├── quarterly.rake │ ├── quarterly │ ├── cbeta_epub2.rb │ ├── change-log-cat.rb │ ├── change-log-font.rb │ ├── changelog.rb │ ├── check-new-canon.rb │ ├── config.rb │ ├── diff-to-html.rb │ ├── epub-main.rb │ ├── epub-template │ │ ├── content.opf.erb │ │ ├── donate.xhtml │ │ ├── epub.css │ │ ├── readme.xhtml │ │ ├── titlepage.xhtml │ │ └── toc.ncx.erb │ ├── html-node.rb │ ├── juanline.rb │ ├── manticore-template-chunks.conf │ ├── manticore-template-notes.conf │ ├── manticore-template-text.conf │ ├── manticore-template-titles.conf │ ├── mobi.rb │ ├── p5a_to_text.rb │ ├── quarterly.rb │ ├── runbook-ebook-cn.rb │ ├── runbook-ebook.rb │ ├── runbook-prepare-cn.rb │ ├── runbook-sphinx-cn.rb │ ├── section-change-log.rb │ ├── section-check.rb │ ├── section-convert.rb │ ├── section-download-ebooks.rb │ ├── section-html.rb │ ├── section-kwic.rb │ ├── section-manticore.rb │ ├── section-prepare.rb │ ├── section-rdb.rb │ ├── section-sphinx.rb │ ├── sphinx-template-chunks.conf │ ├── sphinx-template-notes.conf │ ├── sphinx-template-text.conf │ ├── sphinx-template-titles.conf │ └── update-github.rb │ ├── quarterly_cn.rake │ ├── sa.cpp │ ├── share.rb │ ├── sphinx-notes.rb │ ├── sphinx-share.rb │ ├── sphinx-t2x.rb │ ├── sphinx-titles.rb │ ├── sphinx.rake │ ├── update.rake │ ├── x2h_for_download.html │ ├── x2h_for_download.rb │ ├── x2h_for_ui.rb │ ├── x2h_share.rb │ ├── x2t_for_download.rb │ ├── x2t_for_manticore.rb │ ├── x2t_for_sphinx.rb │ ├── x2x_for_docusky.rb │ ├── xml4docx-styles.yaml │ ├── xml4docx1.rb │ ├── xml4docx2.rb │ └── xml4docx3.rb ├── log └── .keep ├── public ├── 404.html ├── 406-unsupported-browser.html ├── 422.html ├── 500.html ├── api-docs │ ├── api │ │ ├── collections.yaml │ │ ├── collections_x_resources.yaml │ │ ├── resources_x_sections.yaml │ │ ├── sections_x.yaml │ │ └── sections_x_content_units.yaml │ ├── catalog_entry │ │ ├── _.yaml │ │ ├── parameters.yaml │ │ ├── response-examples.yaml │ │ └── response.yaml │ ├── chinese_tools │ │ └── sc2tc.yaml │ ├── common │ │ └── resources.yaml │ ├── download │ │ ├── docusky.yaml │ │ ├── epub-all.yaml │ │ ├── epub.yaml │ │ ├── footnotes.yaml │ │ ├── html_work.yaml │ │ ├── html_work_juan.yaml │ │ ├── mobi-all.yaml │ │ ├── mobi.yaml │ │ ├── pdf-all.yaml │ │ ├── pdf.yaml │ │ └── text.yaml │ ├── export-all_creators-response.yaml │ ├── export │ │ ├── all-creators.yaml │ │ ├── all_creators2.yaml │ │ ├── all_works.yaml │ │ ├── check_list.yaml │ │ ├── creator_strokes.yaml │ │ ├── creator_strokes_works.yaml │ │ ├── dynasty.yaml │ │ ├── dynasty_works.yaml │ │ ├── scope_selector_by_category.yaml │ │ └── scope_selector_by_vol.yaml │ ├── juans │ │ ├── _.yaml │ │ ├── goto-parameters.yaml │ │ ├── goto-response.yaml │ │ ├── goto.md │ │ ├── goto.yaml │ │ ├── parameters.yaml │ │ └── response.yaml │ ├── lines │ │ ├── _.yaml │ │ ├── parameters.yaml │ │ └── response.yaml │ ├── openapi.yaml │ ├── search │ │ ├── _.yaml │ │ ├── all_in_one.yaml │ │ ├── extended.yaml │ │ ├── facet.yaml │ │ ├── facet_canon.yaml │ │ ├── facet_category.yaml │ │ ├── facet_creator.yaml │ │ ├── facet_dynasty.yaml │ │ ├── facet_work.yaml │ │ ├── footnotes-response.yaml │ │ ├── footnotes.yaml │ │ ├── kwic-parameters.yaml │ │ ├── kwic-response.yaml │ │ ├── kwic.yaml │ │ ├── parameters-filter.yaml │ │ ├── parameters-option.yaml │ │ ├── parameters.yaml │ │ ├── response.yaml │ │ ├── sc.yaml │ │ ├── semantic-response.yaml │ │ ├── semantic.yaml │ │ ├── similar-parameters.yaml │ │ ├── similar.yaml │ │ ├── synonym.yaml │ │ ├── title-response.yaml │ │ ├── title.yaml │ │ ├── toc-response-example.yaml │ │ ├── toc-response.yaml │ │ ├── toc.yaml │ │ ├── variants-response.yaml │ │ └── variants.yaml │ ├── word_seg │ │ └── _.yaml │ └── works │ │ ├── _.yaml │ │ ├── parameters.yaml │ │ ├── response.yaml │ │ ├── toc-node.yaml │ │ ├── toc-response.yaml │ │ └── toc.yaml ├── favicon.ico ├── icon.png ├── icon.svg └── robots.txt ├── test ├── application_system_test_case.rb ├── controllers │ ├── .keep │ ├── catalog_entry_controller_test.rb │ ├── chinese_tools_controller_test.rb │ ├── download_controller_test.rb │ ├── export_controller_test.rb │ ├── juans_controller_test.rb │ ├── kwic_controller_test.rb │ ├── lines_controller_test.rb │ ├── report_controller_test.rb │ ├── sphinx_controller_test.rb │ ├── static_pages_controller_test.rb │ ├── toc_node_controller_test.rb │ ├── word_seg_controller_test.rb │ └── works_controller_test.rb ├── fixtures │ ├── .keep │ ├── categories.yml │ ├── gaijis.yml │ ├── goto_abbrs.yml │ ├── juan_lines.yml │ ├── lines.yml │ ├── people.yml │ ├── terms.yml │ ├── toc_nodes.yml │ ├── variants.yml │ ├── works.yml │ └── xml_files.yml ├── helpers │ └── .keep ├── integration │ ├── .keep │ └── download_texts_test.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── category_test.rb │ ├── gaiji_test.rb │ ├── goto_abbr_test.rb │ ├── juan_line_test.rb │ ├── line_test.rb │ ├── person_test.rb │ ├── term_test.rb │ ├── toc_node_test.rb │ ├── variant_test.rb │ ├── work_test.rb │ └── xml_file_test.rb └── test_helper.rb └── vendor └── assets ├── javascripts └── .keep └── stylesheets └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | *.out 8 | *.log 9 | 10 | # Ignore bundler config. 11 | /.bundle 12 | 13 | /config/cb.yml 14 | /config/database.yml 15 | /config/master.key 16 | /config/credentials/cn.key 17 | 18 | /data 19 | 20 | # Ignore the default SQLite database. 21 | /db/*.sqlite3 22 | /db/*.sqlite3-* 23 | 24 | # Ignore all logfiles and tempfiles. 25 | /log/* 26 | !/log/.keep 27 | /tmp 28 | 29 | /public/help 30 | /.vscode 31 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 3.4.2 2 | nodejs 23.5.0 3 | -------------------------------------------------------------------------------- /Capfile: -------------------------------------------------------------------------------- 1 | # Load DSL and set up stages 2 | require 'capistrano/setup' 3 | 4 | # Include default deployment tasks 5 | require 'capistrano/deploy' 6 | 7 | # Include tasks from other gems included in your Gemfile 8 | # 9 | # For documentation on these, see for example: 10 | # 11 | # https://github.com/capistrano/rvm 12 | # https://github.com/capistrano/rbenv 13 | # https://github.com/capistrano/chruby 14 | # https://github.com/capistrano/bundler 15 | # https://github.com/capistrano/rails 16 | # https://github.com/capistrano/passenger 17 | # 18 | require "capistrano/asdf" 19 | require 'capistrano/bundler' 20 | require 'capistrano/rails/assets' 21 | require 'capistrano/rails/migrations' 22 | require 'capistrano/passenger' 23 | 24 | # Load custom tasks from `lib/capistrano/tasks` if you have any defined 25 | Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } 26 | 27 | require "capistrano/scm/git" 28 | install_plugin Capistrano::SCM::Git -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CBETA API 2 | 3 | 法鼓文理學院 使用 Ruby on Rails 開發的 [CBETA API 網站](https://cbdata.dila.edu.tw/stable) Source。 4 | 5 | ## 開發環境 on mac 6 | 7 | 參考 [doc/dev-mac.md](doc/dev-mac.md) 8 | 9 | ## 新主機 環境架設 10 | 11 | 參考 doc/server-setup.md 12 | 13 | ## 資料準備 14 | 15 | 參考 doc/setup.md 16 | 17 | ## CBETA API 換新版 18 | 19 | 參考 doc/new-version.md 20 | 21 | ## 資料夾 22 | 23 | * data: 不放上 git 的資料 24 | * data-static: 要放上 git 的靜態資料 25 | 26 | ## Developer Group 27 | 28 | 開發者、使用者 提問方式: 29 | 30 | * 使用 GitHub 新增的 [Discussions](https://github.com/DILA-edu/cbeta-api/discussions) 功能。 31 | 32 | ## OpenAPI 33 | 34 | 使用 OpenAPI 規格撰寫的文件: 35 | 36 | 37 | ## 參考規範 38 | 39 | * [OpenAPI](https://swagger.io/specification/) 40 | * [Google JSON Style Guide](https://google.github.io/styleguide/jsoncstyleguide.xml) 41 | 42 | ## 使用 CBETA API 開發的 App 43 | 44 | * [CBETA Online](https://cbetaonline.dila.edu.tw) 45 | * [DeerPark 漢文大藏經](https://deerpark.app) 46 | * 非官方 2代 CBETA 電子佛典閱讀器 47 | * UI: 48 | * 使用說明與程式原始碼: 49 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/download.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/juans.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/static_pages.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | */ 14 | /* 15 | @import "bootstrap"; 16 | */ 17 | 18 | div.chapter { 19 | margin-left: 2rem; 20 | } 21 | 22 | div.code pre { 23 | padding: 16px; 24 | overflow: auto; 25 | line-height: 1.45; 26 | background-color: #f6f8fa; 27 | border-radius: 6px; 28 | } 29 | 30 | div.section { 31 | margin-left: 2rem; 32 | } 33 | h2 { 34 | margin-top: 2rem; 35 | font-size: 2.2rem; 36 | } 37 | h3 { 38 | font-size: 1.8rem; 39 | } 40 | 41 | table.table { 42 | width: auto; 43 | } 44 | -------------------------------------------------------------------------------- /app/assets/stylesheets/download.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Download controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/juans.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the juans controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/controllers/canons_controller.rb: -------------------------------------------------------------------------------- 1 | class CanonsController < ApplicationController 2 | def index 3 | r = [] 4 | Canon.all.order(:id2).each do |c| 5 | r << { 6 | uuid: c.uuid, 7 | name: "#{c.id2} #{c.name}", 8 | resourceCount: Work.where(canon: c.id2).where(alt: nil).size 9 | } 10 | end 11 | render json: r 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/chinese_tools_controller.rb: -------------------------------------------------------------------------------- 1 | require 'open3' 2 | class ChineseToolsController < ApplicationController 3 | def sc2tc 4 | cmd = 'opencc -c s2tw' 5 | a = Open3.capture2(cmd, stdin_data: params[:q]) 6 | render plain: a[0] 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/concerns/cbeta_string.rb: -------------------------------------------------------------------------------- 1 | class CbetaString 2 | HALF_PUNCS = "()*.[]" 3 | 4 | # 全形標點 按內碼順序排列 5 | FULL_PUNCS = '—…‧─│┬▆△◎ 、。〃〈〉《》「」『』【】〔〕〖〗︰!()*+,-./:;<=>?[]~' 6 | 7 | PUNCS = HALF_PUNCS + FULL_PUNCS 8 | 9 | def initialize(allow_digit: false, allow_space: true, allow_comma: false) 10 | s = PUNCS 11 | s = Regexp.quote(s) 12 | s << '\n' 13 | s << '\d' unless allow_digit 14 | 15 | # kwic query 語法 允許 半形逗點 16 | s << ',' unless allow_comma 17 | 18 | # 預設 保留 半形空格,否則會搜不到:Pāli Text Society 19 | s << ' ' unless allow_space 20 | 21 | @regexp = /[#{s}]/ 22 | @regexp2 = /[#{s}]\z/ 23 | end 24 | 25 | def end_with_puncs?(s) 26 | s.match?(@regexp2) 27 | end 28 | 29 | def remove_puncs(s) 30 | s.gsub(@regexp, '') 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/controllers/download_controller.rb: -------------------------------------------------------------------------------- 1 | class DownloadController < ApplicationController 2 | def index 3 | fn = Rails.root.join('data', 'download', params[:id]) 4 | logger.info "download_controller.rb, fn: #{fn}" 5 | if File.file?(fn) and File.readable?(fn) 6 | send_file(fn) 7 | else 8 | my_render_error(404, "File not found.") 9 | end 10 | rescue => e 11 | my_render_error(500, $!) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/word_seg_controller.rb: -------------------------------------------------------------------------------- 1 | require 'tempfile' 2 | class WordSegController < ApplicationController 3 | 4 | def index 5 | return unless params.key? :t 6 | r = WordSegService.new.run(params[:t]) 7 | if r.success? 8 | render plain: r.result 9 | else 10 | render plain: r.errors 11 | end 12 | end 13 | 14 | def run 15 | if params[:payload].nil? 16 | render json: { 17 | error: { 18 | code: 400, 19 | message: "缺少 payload 參數" 20 | } 21 | } 22 | return 23 | end 24 | 25 | r = WordSegService.new.run(params[:payload]) 26 | if r.success? 27 | puts r.result 28 | r.result.sub!(/^\//, '') 29 | render json: { segmented: r.result.split('/') } 30 | else 31 | render json: { 32 | error: { message: r.errors } 33 | } 34 | end 35 | end 36 | 37 | end -------------------------------------------------------------------------------- /app/errors/cbeta_error.rb: -------------------------------------------------------------------------------- 1 | class CbetaError < StandardError 2 | attr :code 3 | def initialize(code) 4 | @code = code 5 | end 6 | end -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | def debug(s) 3 | Rails.logger.debug s 4 | end 5 | 6 | # 將數字轉為加上千位號的字串 7 | def n2c(n) 8 | ActionView::Base.new.number_to_currency(n, unit: '', precision: 0) 9 | end 10 | 11 | def warn(s) 12 | Rails.logger.warn s 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /app/helpers/download_helper.rb: -------------------------------------------------------------------------------- 1 | module DownloadHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/export_helper.rb: -------------------------------------------------------------------------------- 1 | module ExportHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/juans_helper.rb: -------------------------------------------------------------------------------- 1 | module JuansHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/lines_helper.rb: -------------------------------------------------------------------------------- 1 | module LinesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/sphinx_helper.rb: -------------------------------------------------------------------------------- 1 | module SphinxHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/static_pages_helper.rb: -------------------------------------------------------------------------------- 1 | module StaticPagesHelper 2 | def link_to_url(url, label=nil) 3 | if label.nil? 4 | label = File.join(root_url, url) 5 | end 6 | 7 | url = File.join(root_url, url) 8 | "#{label}".html_safe 9 | end 10 | 11 | def link_to_path(path, label=nil, params) 12 | if params.nil? 13 | url = path 14 | else 15 | url = "#{path}?#{params.to_query}" 16 | end 17 | 18 | if label.nil? 19 | label = File.join(root_url, url) 20 | end 21 | 22 | url = File.join(root_url, url) 23 | "#{label}".html_safe 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/helpers/toc_node_helper.rb: -------------------------------------------------------------------------------- 1 | module TocNodeHelper 2 | def get_toc_by_work_id(w) 3 | canon = CBETA.get_canon_id_from_work_id(w) 4 | fn = Rails.root.join('data', 'toc', canon, w+'.json') 5 | return nil unless File.exist? fn 6 | 7 | s = File.read(fn) 8 | JSON.parse(s) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/helpers/works_helper.rb: -------------------------------------------------------------------------------- 1 | module WorksHelper 2 | def get_work_info_by_id(n) 3 | if n.size > 6 4 | n.sub(/^(#{CBETA::CANON})\d{2,3}n(.*)$/, '\1\2') 5 | end 6 | Work.get_info_by_id(n) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/app/mailers/.keep -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/app/models/.keep -------------------------------------------------------------------------------- /app/models/README.md: -------------------------------------------------------------------------------- 1 | * CatalogEntry: 藏經目錄 2 | * JuanLine: 冊號、經號、卷號、行號 對照表,供 Goto 使用。 3 | * Line: 供取得「行號範圍文字」 4 | * TocNode: 供「經目查詢」時也搜尋作品內目次 5 | * Work: 作品 6 | * XmlFile 7 | * 記錄一部作品的「第一個 XML 檔」與「起始卷數」。 8 | -------------------------------------------------------------------------------- /app/models/analytics_record.rb: -------------------------------------------------------------------------------- 1 | class AnalyticsRecord < ApplicationRecord 2 | self.abstract_class = true 3 | connects_to database: { writing: :analytics, reading: :analytics } 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | connects_to database: { writing: :primary, reading: :primary } 4 | end 5 | -------------------------------------------------------------------------------- /app/models/canon.rb: -------------------------------------------------------------------------------- 1 | class Canon < ActiveRecord::Base 2 | validates :id2, uniqueness: true 3 | validates :uuid, uniqueness: true 4 | end 5 | -------------------------------------------------------------------------------- /app/models/catalog_entry.rb: -------------------------------------------------------------------------------- 1 | class CatalogEntry < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/models/category.rb: -------------------------------------------------------------------------------- 1 | class Category < ApplicationRecord 2 | def self.get_n_by_name(name) 3 | c = Category.find_by name: name 4 | return nil if c.nil? 5 | c.n 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/gaiji.rb: -------------------------------------------------------------------------------- 1 | class Gaiji < ActiveRecord::Base 2 | def self.replace_pua_with_zzs(text) 3 | text.gsub(/[\u{F0000}-\u{FFFFF}]/) do 4 | pua = $& 5 | g = self.find_by(pua: pua) 6 | g.nil? ? pua : g.zzs 7 | end 8 | end 9 | 10 | def self.replace_zzs_with_pua(q) 11 | return nil if q.nil? 12 | return q unless q.include? '[' 13 | r = q.gsub(/\[[^\]]+\]/) do |s| 14 | g = self.find_by zzs: s 15 | g.nil? ? s : g.pua 16 | end 17 | r 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/models/goto_abbr.rb: -------------------------------------------------------------------------------- 1 | class GotoAbbr < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/models/juan_line.rb: -------------------------------------------------------------------------------- 1 | class JuanLine < ActiveRecord::Base 2 | def self.find_by_vol(vol) 3 | jl = JuanLine.where(vol: vol).order(:lb).first 4 | if jl.nil? 5 | raise CbetaError.new(404), "無此冊號: #{vol}" 6 | end 7 | lb = jl.lb.sub(/^0000/, '') 8 | return jl.work, jl.juan, lb 9 | end 10 | 11 | # 取得某經、某卷 的 第一個 lb 及其冊數 12 | def self.get_first_lb_by_work_juan(work, juan) 13 | jl = JuanLine.where("work=? AND juan=?", work, juan).first 14 | raise CbetaError.new(404), "找不到 佛典編號: #{work}, 卷號: #{juan}" if jl.nil? 15 | 16 | lb = jl.lb 17 | 18 | # LC0001 的第一頁是 a001, 19 | # 為了讓它的排序在 0001 之前, JuanLine 在 lb 前加了 0000 20 | # 所以這裡要去掉。 21 | # 但是 GA0077 的第一頁又真的是 0000, 所以要先判斷 lb 的 size 22 | lb.delete_prefix!('0000') if lb.size > 7 23 | 24 | return jl.vol, lb 25 | end 26 | 27 | def self.get_juan_by_vol_work_lb(vol, work, lb) 28 | jl = JuanLine.where("vol=? AND work=? AND lb<=?", vol, work, lb).last 29 | return nil if jl.nil? 30 | return jl.juan 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/models/lb_map.rb: -------------------------------------------------------------------------------- 1 | class LbMap < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/models/person.rb: -------------------------------------------------------------------------------- 1 | class Person < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /app/models/place.rb: -------------------------------------------------------------------------------- 1 | class Place < ActiveRecord::Base 2 | has_and_belongs_to_many :works 3 | end 4 | -------------------------------------------------------------------------------- /app/models/term.rb: -------------------------------------------------------------------------------- 1 | class Term < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /app/models/toc_node.rb: -------------------------------------------------------------------------------- 1 | class TocNode < ActiveRecord::Base 2 | def label_path 3 | tokens = [] 4 | t = self 5 | until t.nil? 6 | tokens.unshift t.label 7 | t = TocNode.find_by n: t.parent 8 | end 9 | tokens.join('/') 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/models/variant.rb: -------------------------------------------------------------------------------- 1 | class Variant < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /app/models/visit.rb: -------------------------------------------------------------------------------- 1 | class Visit < AnalyticsRecord 2 | attribute :count, :integer, default: 0 3 | end 4 | -------------------------------------------------------------------------------- /app/models/xml_file.rb: -------------------------------------------------------------------------------- 1 | # 佛典預設只由一個 xml 組成,並且由第一卷開始, 2 | # 如果不是的話,就在 XmlFile 之中記錄。 3 | class XmlFile < ActiveRecord::Base 4 | end 5 | -------------------------------------------------------------------------------- /app/services/authority_service.rb: -------------------------------------------------------------------------------- 1 | class AuthorityService 2 | attr_reader :catalog, :persons 3 | 4 | def read_catalog 5 | @catalog = {} 6 | folder = Rails.configuration.x.work_info 7 | Dir["#{folder}/*.json"].each do |f| 8 | works = JSON.load_file(f) 9 | @catalog.merge!(works) 10 | end 11 | end 12 | 13 | def read_persons 14 | @persons = {} 15 | fn = File.join( 16 | Rails.configuration.x.authority, 17 | 'authority_person', 18 | 'Buddhist_Studies_Person_Authority.xml' 19 | ) 20 | doc = File.open(fn) { |f| Nokogiri::XML(f) } 21 | doc.remove_namespaces! 22 | doc.xpath('//person').each do |person| 23 | id = person['id'] 24 | @persons[id] = person_xml_to_h(person) 25 | end 26 | end 27 | 28 | private 29 | 30 | def person_xml_to_h(person) 31 | r = {} 32 | aliases = [] 33 | person.xpath('persName').each do |name| 34 | s = name.content 35 | if not name.key?('type') 36 | r[:regular_name] = s if name['lang'] == 'zho-Hant' 37 | elsif name['type'] == 'alternative' 38 | aliases << s 39 | end 40 | end 41 | r[:aliases] = aliases unless aliases.empty? 42 | r 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /app/services/int_to_zht.rb: -------------------------------------------------------------------------------- 1 | class IntToZht 2 | NUMS = %w[零 一 二 三 四 五 六 七 八 九] 3 | UNITS = %w[十 百 千] 4 | 5 | def self.convert(num) 6 | return NUMS[0] if num == 0 7 | 8 | str = num.to_s 9 | length = str.length 10 | result = "" 11 | 12 | str.chars.each_with_index do |char, index| 13 | digit = char.to_i 14 | position = length - index - 1 15 | 16 | if digit != 0 17 | result += NUMS[digit] 18 | result += UNITS[position - 1] if position > 0 19 | elsif position == 1 && result[-1] != NUMS[0] 20 | result += NUMS[0] 21 | end 22 | end 23 | 24 | result.gsub(/一十/, '十').gsub(/零+$/, '') 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/services/manticore_service.rb: -------------------------------------------------------------------------------- 1 | class ManticoreService 2 | def initialize 3 | @v = Rails.configuration.cb.v 4 | end 5 | 6 | def open 7 | @client = Mysql2::Client.new(:host => 0, :port => 9307, encoding: 'utf8mb4') 8 | if @client.nil? 9 | msg = "開啟 MySQL connection 回傳 nil" 10 | logger.fatal msg 11 | raise CbetaError.new(500), msg 12 | end 13 | @client 14 | end 15 | 16 | def close 17 | return if @client.nil? 18 | @client.close 19 | @client = nil 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/services/matrix.rb: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/vincentchu/1041980 2 | class Matrix 3 | 4 | IndexOverflow = Class.new(StandardError) 5 | 6 | attr_reader :dims, :nrows, :ncols 7 | 8 | def initialize(mm, nn) 9 | @dims = [mm, nn] 10 | @nrows = mm 11 | @ncols = nn 12 | @m = Array.new(mm) 13 | 14 | (1..mm).each {|i| @m[i-1] = Array.new(nn, 0)} 15 | end 16 | 17 | def inspect 18 | @m.inject("") do |str, row| 19 | str += row.collect {|v| sprintf("%5d", v)}.join(" ") + "\n" 20 | end 21 | end 22 | 23 | def [](i, j) 24 | raise IndexOverflow if ((i >= nrows) || (j >= ncols)) 25 | 26 | @m[i][j] 27 | end 28 | 29 | def []=(i, j, k) 30 | raise IndexOverflow if ((i >= nrows) || (j >= ncols)) 31 | 32 | @m[i][j] = k 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /app/services/unicode_service.rb: -------------------------------------------------------------------------------- 1 | class UnicodeService 2 | def initialize 3 | @u2 = Unihan2.new 4 | end 5 | 6 | # 決定是否採用 unicode 字元 或 unicode 通用字 7 | def gaiji_unicode(g, normalize: True) 8 | u = g['uni_char'] 9 | return u unless u.blank? 10 | 11 | return nil unless normalize 12 | 13 | r = g['norm_uni_char'] 14 | return r unless r.blank? 15 | 16 | r = g['norm_big5_char'] 17 | return r unless r.blank? 18 | 19 | nil 20 | end 21 | 22 | def level1?(code) 23 | return false if code.nil? 24 | # Unicode 3.0 以內 在 mobile 可以正確顯示 25 | v = @u2.ver(code) 26 | raise CbetaError.new(500), "Unihan2.ver 回傳 nil, code: #{code}" if v.nil? 27 | v <= 3 28 | end 29 | 30 | def level2?(code) 31 | return false if code.nil? 32 | # Unicode 10 以內 在 desktop 有字型可以顯示 (預設可能沒有,需要安裝字型) 33 | @u2.ver(code) <= 10 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/views/juans/index.html.erb: -------------------------------------------------------------------------------- 1 | <%= response %> -------------------------------------------------------------------------------- /app/views/layouts/_navbar_catalog.html.haml: -------------------------------------------------------------------------------- 1 | %li.nav-item.dropdown 2 | %a#navbarDropdown.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :href => "#", :role => "button"} 3 | Catalog 4 | .dropdown-menu{"aria-labelledby" => "navbarDropdown"} 5 | = link_to '目錄', { controller: 'static_pages', action: 'catalog'}, class: 'dropdown-item' 6 | = link_to '佛典範圍搜尋', { controller: 'static_pages', action: 'works'}, class: 'dropdown-item' 7 | = link_to '以作譯者搜尋', { controller: 'static_pages', action: 'creators'}, class: 'dropdown-item' 8 | = link_to '以時間搜尋', { controller: 'static_pages', action: 'time'}, class: 'dropdown-item' 9 | -------------------------------------------------------------------------------- /app/views/report/_datepicker.haml: -------------------------------------------------------------------------------- 1 | .row.justify-content-center 2 | .col-auto 3 | %p 4 | = form_with(url: url, method: :get, local: true) do |f| 5 | 起始日期: 6 | = f.text_field :d1 7 | 結束日期: 8 | = f.text_field :d2 9 | = f.submit "送出" 10 | -------------------------------------------------------------------------------- /app/views/report/daily.haml: -------------------------------------------------------------------------------- 1 | .row.justify-content-center 2 | .col-auto 3 | %h1 API 存取統計表 Group by Date 4 | %p.text-center= link_to 'Export CSV', report_daily_path(format: "csv") 5 | %p 6 | 資料庫總筆數: 7 | =number_with_delimiter(Visit.count) 8 | %br 9 | 存取總數: 10 | =number_with_delimiter(@sum) 11 | %br 12 | 單日最高: 13 | =number_with_delimiter(@max) 14 | %br 15 | 單日平均: 16 | =number_with_delimiter(@avg) 17 | .row.justify-content-center 18 | .col-auto 19 | = will_paginate @visit_keys, renderer: WillPaginate::ActionView::BootstrapLinkRenderer 20 | %table.table-striped 21 | %tr 22 | %th Date 23 | %th Count 24 | - @visit_keys.each do |k| 25 | - v = @visits[k] 26 | %tr 27 | %td{ style: 'padding-right: 2em' }= k 28 | %td.text-right= number_with_delimiter(v) 29 | -------------------------------------------------------------------------------- /app/views/report/index.haml: -------------------------------------------------------------------------------- 1 | %h1 統計報表 2 | %h2 全集成 統計數字 3 | 4 | %p= link_to_url '/report/total' 5 | 6 | %p CBETA 收錄內容可分為兩大類: 7 | %ul 8 | %li textbody (本文) 9 | %li non-textbody (非本文): 例如 ZWa001 (緣起)、ZWa002 (卷首語)、ZWa003 (目錄) 10 | 11 | %p 回傳資料 12 | %ul 13 | %li 14 | total (全部) 15 | %ul 16 | %li works_all (典籍部數,含 non-textbody) 17 | %li works_main (典籍部數,不含 non-textbody) 18 | %li juans_all (典籍卷數,含 non-textbody) 19 | %li juans_main (典籍卷數,不含 non-textbody) 20 | %li cjk_chars_all (CJK 字元數,含 non-textbody) 21 | %li cjk_chars_main (CJK 字元數,不含 non-textbody) 22 | %li en_words_all (英文、梵巴轉寫 word 數量,含 non-textbody) 23 | %li en_words_main (英文、梵巴轉寫 word 數量,不含 non-textbody) 24 | %li 新標卷數 25 | %li 新標部數 26 | %li CBETA_新標卷數 (原書無新標,由 CBETA 執行製作) 27 | %li CBETA_新標部數 (原書無新標,由 CBETA 執行製作) 28 | %li 29 | by_canon (分藏別) 30 | %ul 31 | %li 欄位同上 32 | -------------------------------------------------------------------------------- /app/views/report/referer.haml: -------------------------------------------------------------------------------- 1 | .row.justify-content-center 2 | .col-auto 3 | %h1 API 存取統計表 Group by Referer 4 | 5 | = render partial: "datepicker" , locals: { url: report_referer_path } 6 | 7 | .row.justify-content-center 8 | .col-auto 9 | %p 10 | = "日期範圍:#{@d1} ~ #{@d2}" 11 | = surround '(', ')' do 12 | =link_to 'Export CSV', report_referer_path(format: 'csv', d1: @d1, d2: @d2) 13 | %p 14 | Total: 15 | = number_with_delimiter(@total) 16 | %table.table-striped.table-bordered 17 | %tr 18 | %th Referer 19 | %th Count 20 | - total = 0 21 | - @visits.each do |a| 22 | - total += a[1] 23 | %tr 24 | %td.fit= a[0] 25 | %td.text-right.fit= number_with_delimiter(a[1]) 26 | :javascript 27 | $( function() { 28 | report_init_datepicker() 29 | } ); 30 | -------------------------------------------------------------------------------- /app/views/report/url.haml: -------------------------------------------------------------------------------- 1 | .row.justify-content-center 2 | .col-auto 3 | %h1 API 存取統計表 Group by URL 4 | 5 | = render partial: "datepicker" , locals: { url: report_url_path } 6 | 7 | .row.justify-content-center 8 | .col-auto 9 | %p 10 | = "日期範圍:#{@d1} ~ #{@d2}" 11 | = surround '(', ')' do 12 | =link_to 'Export CSV', report_url_path(format: 'csv', d1: @d1, d2: @d2) 13 | %p 14 | Total: 15 | = number_with_delimiter(@total) 16 | %table.table-striped.table-bordered 17 | %tr 18 | %th URL 19 | %th Referer 20 | %th Count 21 | - total = 0 22 | - @visits.each do |a| 23 | - total += a[1] 24 | %tr 25 | %td.fit= a[0][0] 26 | %td.fit= a[0][1] 27 | %td.text-right.fit= number_with_delimiter(a[1]) 28 | :javascript 29 | $( function() { 30 | report_init_datepicker() 31 | } ); 32 | -------------------------------------------------------------------------------- /app/views/static_pages/_arg-cache.haml: -------------------------------------------------------------------------------- 1 | %tr 2 | %td cache 3 | %td 選項 4 | %td 指定是否使用 cache. 1: 使用 cache; 0: 不使用 cache. 預設值為 1. 5 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-byline.haml: -------------------------------------------------------------------------------- 1 | %h2#byline 作譯者 2 | 3 | %p 例 T01n0001_p0001a03 4 | .code 5 | %pre 6 | :escaped 7 | 8 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-classes.haml: -------------------------------------------------------------------------------- 1 | %h2#classes Classes 2 | 3 | %h3#class_circle circle 4 | %p 文字外包圓圈,例 G104n2254_p0335a19 5 | .code 6 | %pre 7 | :escaped 8 | 甲 9 | 10 | %h3#class_pl_size pl-{size} 11 | %p 例如 pl-2 表示 padding-left:2em。 12 | %p 目前只有出現 pl-2 和 pl-4 這二種,CBReader 支援 pl-1 至 pl-8 八種。 13 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-copyright.haml: -------------------------------------------------------------------------------- 1 | %h2#copyright 版權資訊 2 | 3 | %p 在各卷 HTML 最後有版權資訊,例 T0001_001: 4 | .code 5 | %pre 6 | :escaped 7 | 16 | 17 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-facsimile.haml: -------------------------------------------------------------------------------- 1 | %h2#facsimile 連結原書掃描圖 2 | 3 | %p 例 T42n1828_p0311a01 4 | .code 5 | %pre 6 | :escaped 7 | 8 | 9 | %p 10 | 前端可根據以上標記連至 大正藏掃描圖: 11 | =link_to nil, 'https://dia.dila.edu.tw/uv3/index.html?id=Tv42p0312' 12 | 13 | %p 其他例子還有: 14 | %p 連 高麗藏 15 | .code 16 | %pre 17 | :escaped 18 | 19 | 20 | %p 連 國圖善本 21 | .code 22 | %pre 23 | :escaped 24 | 25 | 26 | %p 連 佛寺志 27 | .code 28 | %pre 29 | :escaped 30 | 31 | 32 | %p 連 嘉興藏 33 | .code 34 | %pre 35 | :escaped 36 | 37 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-graphic.haml: -------------------------------------------------------------------------------- 1 | %h2#graphic 圖片 2 | %p 例 T16n0719_p0845c19 3 | .code 4 | %pre 5 | :escaped 6 | 7 | 8 | %p src 屬性直接指到 CBETA 公開放在 GitHub 上的圖片。 -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-head.haml: -------------------------------------------------------------------------------- 1 | %h2#head 章節標題 2 | 3 | %p 第一層章節標題,例 T01n0001_p0001a02 4 | .code 5 | %pre 6 | :escaped 7 |

長阿含經序

8 | 9 | %p 第二層章節標題,例 T01n0001_p0001b11 10 | .code 11 | %pre 12 | :escaped 13 |

(一)第一分初大本經第一

14 | 15 | %p 依此類推。 -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-juan.haml: -------------------------------------------------------------------------------- 1 | %h2#juan 卷資訊 2 | 3 | %p 卷首資訊,例 T01n0001_p0001b07 4 | .code 5 | %pre 6 | :escaped 7 |

佛說長阿含經卷第一

8 | 9 | %p 卷尾資訊,例 T01n0001_p0011a01 10 | .code 11 | %pre 12 | :escaped 13 |

佛說長阿含經卷第一

14 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-lg.haml: -------------------------------------------------------------------------------- 1 | %h2#lg 偈頌 2 | %h3 規則偈頌 3 | %p 例 T01n0001_p0001c03: 4 | .code 5 | %pre 6 | :escaped 7 |
8 |
9 |
「比丘集法堂,
10 |
講說賢聖論;
11 |
12 | ... 13 |
14 |
無上天人尊,
15 |
記於過去佛。」
16 |
17 |
18 | %ul 19 | %li <div class="lg"> 表示這是偈頌 (或詩詞) 20 | %li <div class="lg regular"> 表示這是規則偈頌,可使用表格對齊。 21 | %li <div class="lg-row"> 偈頌使用表格對齊時,相當於一個 tr (table row)。 22 | %li <div class="lg-cell"> 偈頌使用表格對齊時,相當於一個 td (table cell)。 23 | 24 | %h3 詞、賦 25 | %p 例 GA001n0002_p0240a11 26 | .code 27 | %pre 28 | :escaped 29 |
30 |
31 |
今偏重者愛昔先民之重由樸由純
32 |
33 |
34 |
白骨兮徒自朽 方寸心兮何所憶
35 |
36 |
37 | 38 | %p <div class="lg"> 沒有 regular,表示是一行一行的不規則詞、賦,不能用 table 對齊。 -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-linehead.haml: -------------------------------------------------------------------------------- 1 | %h2#linehead 行號 2 | %p 例如 T01n0001_p0001a01: 3 | .code 4 | %pre 5 | :escaped 6 | T01n0001_p0001a01 7 | %p 行號本來不應該在本文中出現,這裡將行號包在 span 裡,方便 UI 控制是否顯示行號。 8 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-link.haml: -------------------------------------------------------------------------------- 1 | %h2#links 連結 2 | 3 | %p 例 Y08n0008_p0007a09 4 | .code 5 | %pre 6 | :escaped 7 | 8 | 七八二經 9 | 10 | 11 | %p class="cbeta-link" 表示這是連至 CBETA。 12 | %p data-linehead 屬性放的是 CBETA 行首資訊。 13 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-p.haml: -------------------------------------------------------------------------------- 1 | %h2#p 段落 2 | 3 | %p 例 T01n0001_p0001a05 4 | .code 5 | %pre 6 | :escaped 7 |

夫宗極絕於稱謂....則異途同趣矣。

-------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-person.haml: -------------------------------------------------------------------------------- 1 | %hr 2 | %h2#person 人名 3 | 4 | %p 例 GA009n0008_p0006a04 5 | .code 6 | %pre 7 | :escaped 8 |
9 | 周應賓 10 | 11 | 12 | %p id="person_start_1" 表示這是第一個人名的開始。 13 | %p class="person_start" 表示這是人名的起點。 14 | %p data-key="A006952" 對應到 Authority ID. 15 | %p id="person_end_1" 表示這是第一個人名的結束。 16 | %p class="person_end" 表示這是人名的結束點。 17 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-place.haml: -------------------------------------------------------------------------------- 1 | %h2#person 地名 2 | 3 | %p 例 GA009n0008_p0003a02 4 | .code 5 | %pre 6 | :escaped 7 | 8 | 普陀 9 | 10 | 11 | %p id="place_start_1" 表示這是第一個地名的開始。 12 | %p class="place_start" 表示這是地名的起點。 13 | %p data-key="PL13847" 對應到 Authority ID. 14 | %p id="place_end_1" 表示這是第一個地名的結束。 15 | %p class="place_end" 表示這是地名的結束點。 16 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-punc.haml: -------------------------------------------------------------------------------- 1 | %h2#punc 標點 2 | %p 每個標點片段都會包在 <span class="pc"> 裡面,例 T01n0001_p0001a05 3 | .code 4 | %pre 5 | :escaped 6 | 夫宗極絕於稱謂 7 | %p CBETA 目前收錄的佛典,尚未全部都有新式標點,有三種情況: 8 | %ul 9 | %li 新式標點 10 | %li 原書標點 11 | %li AI 標點 12 | 13 | %h3 CBETA 14 | %p 這會在 body 下的第一層 div 中記錄,data-punc="CBETA" 表示這是由 CBETA 製作的新式標點,例如 T0001_001 15 | .code 16 | %pre 17 | :escaped 18 |
19 | 20 | %h3 DILA 21 | %p data-punc="DILA" 表示這是由 法鼓文理學院 製作的新式標點,例 GA0008_001: 22 | .code 23 | %pre 24 | :escaped 25 |
26 | 27 | %h3 AI 28 | %p 29 | data-punc="AI" 表示使用 30 | = surround '「', '」' do 31 | =link_to '古籍酷 自动标点', 'https://gj.cool/about?tab=punct#punctuation' 32 | 製作的新式標點初稿,例如 X0008_001: 33 | .code 34 | %pre 35 | :escaped 36 |
37 | 38 | %h3 orig 39 | %p data-punc="orig" 表示是原書的標點,例 A1057_001: 40 | .code 41 | %pre 42 | :escaped 43 |
44 | -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-table.haml: -------------------------------------------------------------------------------- 1 | %h2#table 表格 2 | %p 例 T49n2035_p0158c17: 3 | .code 4 | %pre 5 | :escaped 6 |
7 |
8 |
大品(晉羅什譯)
9 |
第一會鷲峯山說四百卷(七十七品單譯)
10 |
11 |
12 |
放光(晉羅叉譯)
13 |
14 | ... 15 |
16 | 17 | %p <div class="bip-table"> 對應 HTML table 元素。 18 | %p <div class='bip-table-row'> 對應 HTML tr 元素。 19 | %p <div class='bip-table-cell'> 對應 HTML td 元素。 -------------------------------------------------------------------------------- /app/views/static_pages/_html-for-ui-text.haml: -------------------------------------------------------------------------------- 1 | %h2#text 文字 2 | %p 每個文字片段都會以 <span class="t"> 包起來,例如 T01n0001_p0001a02: 3 | .code 4 | %pre 5 | :escaped 6 | 7 | %ul 8 | %li l="0001a02" 是這個文字片段所在行號。 9 | %li w="5" 是這個文字片段在本行文字的起始位置。以此例來說,本行文字是「長阿含經序」,因此「序」是本行的第5個字。 10 | -------------------------------------------------------------------------------- /app/views/static_pages/_search-aio-q.haml: -------------------------------------------------------------------------------- 1 | %p 2 | 要搜尋的關鍵字。(標點符號會被去除,包括半形小括號) 3 | %p 4 | 也可使用 5 | =link_to 'Extended 語法', controller: 'static_pages', action: 'search_extended' 6 | 。例如: 7 | %ul 8 | %li 9 | AND: 10 | =link_to_url '/search/all_in_one?q="法鼓" "迦葉"' 11 | %li 12 | OR: 13 | =link_to_url '/search/all_in_one?q="法鼓" | "迦葉"' 14 | %li 15 | NOT: 16 | =link_to_url '/search/all_in_one?q="迦葉" !"迦葉佛"' 17 | %li 18 | NEAR: 19 | %ul 20 | %li 21 | =link_to_url '/search/all_in_one?q="法鼓" NEAR/7 "迦葉"' 22 | (NEAR/ 後面的數字 表示兩個關鍵詞中間的距離) 23 | %li 24 | NEAR 多個詞: 25 | =link_to_url '/search/all_in_one?q="老子" NEAR/7 "道" NEAR/3 "經"' 26 | %li 27 | Exclude 28 | %ul 29 | %li 30 | 排除前搭配 31 | =link_to_url '/search/all_in_one?q="直心" -"正直心"' 32 | %li 33 | 排除後搭配 34 | =link_to_url '/search/all_in_one?q="舍利" -"舍利弗"' 35 | %p 關鍵字詞中若含:單引號、雙引號、半形減號,需 escape,例如: 36 | %ul 37 | %li 38 | 搜尋 samantato AND 'nantanāvāptiśāsani 39 | =link_to_url %q(/search/all_in_one?q="samantato" "\%27nantanāvāptiśāsani") 40 | %li 41 | 搜尋 Your AND "mang-kun" 42 | =link_to_url %q(/search/all_in_one?q="Your" "\"mang\-kun\"") 43 | -------------------------------------------------------------------------------- /app/views/static_pages/_search-arg-paginate.haml: -------------------------------------------------------------------------------- 1 | %tr 2 | %td rows 3 | %td 選項 4 | %td 每頁回傳筆數,預設為 20。 5 | %tr 6 | %td start 7 | %td 選項 8 | %td 分頁回傳起始位置,預設為 0。 9 | -------------------------------------------------------------------------------- /app/views/static_pages/_sphinx-aio-q.haml: -------------------------------------------------------------------------------- 1 | %p 2 | 要搜尋的關鍵字。(標點符號會被去除,包括半形小括號) 3 | %p 4 | 也可使用 5 | =link_to 'Extended 語法', controller: 'static_pages', action: 'sphinx_extended' 6 | 。例如: 7 | %ul 8 | %li 9 | AND: 10 | =link_to_url '/sphinx/all_in_one?q="法鼓" "迦葉"' 11 | %li 12 | OR: 13 | =link_to_url '/sphinx/all_in_one?q="法鼓" | "迦葉"' 14 | %li 15 | NOT: 16 | =link_to_url '/sphinx/all_in_one?q="迦葉" !"迦葉佛"' 17 | %li 18 | NEAR: 19 | %ul 20 | %li 21 | =link_to_url '/sphinx/all_in_one?q="法鼓" NEAR/7 "迦葉"' 22 | (NEAR/ 後面的數字 表示兩個關鍵詞中間的距離) 23 | %li 24 | NEAR 多個詞: 25 | =link_to_url '/sphinx/all_in_one?q="老子" NEAR/7 "道" NEAR/3 "經"' 26 | %li 27 | Exclude 28 | %ul 29 | %li 30 | 排除前搭配 31 | =link_to_url '/sphinx/all_in_one?q="直心" -"正直心"' 32 | %li 33 | 排除後搭配 34 | =link_to_url '/sphinx/all_in_one?q="舍利" -"舍利弗"' 35 | %p 關鍵字詞中若含:單引號、雙引號、半形減號,需 escape,例如: 36 | %ul 37 | %li 38 | 搜尋 samantato AND 'nantanāvāptiśāsani 39 | =link_to_url %q(/sphinx/all_in_one?q="samantato" "\%27nantanāvāptiśāsani") 40 | %li 41 | 搜尋 Your AND "mang-kun" 42 | =link_to_url %q(/sphinx/all_in_one?q="Your" "\"mang\-kun\"") 43 | -------------------------------------------------------------------------------- /app/views/static_pages/callback.html.erb: -------------------------------------------------------------------------------- 1 |

callback

2 |

JsonP 的封裝字串,用於 Cross-site Ajax 操作時使用。

3 |

4 | 例如: 5 | <%= link_to_url '/sphinx?q=法鼓&callback=abc' %> 6 |

7 |

回傳:

8 |
 9 | /**/abc(...)
10 | 
-------------------------------------------------------------------------------- /app/views/static_pages/catalog.html.haml: -------------------------------------------------------------------------------- 1 | %h1 目錄 2 | %h2 一、根目錄 3 | %p 4 | 取得 CBETA 各種目錄: 5 | =link_to_url '/catalog_entry?q=root' 6 | 7 | %h2 二、CBETA 部類目錄 8 | %p 9 | 取得 CBETA 部類目錄: 10 | =link_to_url '/catalog_entry?q=CBETA' 11 | 12 | %p 回傳: 13 | %pre 14 | :preserve 15 | { 16 | "num_found": 21, 17 | "results": [ 18 | { 19 | "n": "CBETA.001", 20 | "label": "01 阿含部類 T01-02,25,33 etc." 21 | }, 22 | ... 23 | { 24 | "n": "CBETA.021", 25 | "label": "21 新編部類 ZS01, ZW01-09, I01" 26 | } 27 | ] 28 | } 29 | 30 | %h2 三、原書目錄 31 | %p 32 | 取得原書目錄: 33 | =link_to_url '/catalog_entry?q=orig' 34 | 35 | %p 36 | 可取得某一部藏經的原書目錄,例如要取得其中《大正藏》原書目錄: 37 | =link_to_url "/catalog_entry?q=orig-T" 38 | 39 | %p 40 | 其他各藏,依此類推在 41 | %code 42 | "orig-" 43 | 之後加上藏經 ID。 44 | 45 | %h2 四、回傳欄位 46 | .chapter 47 | =render partial: 'catalog-return' 48 | -------------------------------------------------------------------------------- /app/views/static_pages/catalog_index.haml: -------------------------------------------------------------------------------- 1 | %h1 Catalog 2 | %ul 3 | %li= link_to '目錄', { controller: 'static_pages', action: 'catalog'} 4 | %li= link_to '佛典範圍搜尋', { controller: 'static_pages', action: 'works'} 5 | %li= link_to '以作譯者搜尋', { controller: 'static_pages', action: 'creators'} 6 | %li= link_to '以時間搜尋', { controller: 'static_pages', action: 'time'} 7 | -------------------------------------------------------------------------------- /app/views/static_pages/categories.html.haml: -------------------------------------------------------------------------------- 1 | %h1 CBETA 部類 2 | %ul 3 | %li 阿含部類 4 | %li 本緣部類 5 | %li 般若部類 6 | %li 法華部類 7 | %li 華嚴部類 8 | %li 寶積部類 9 | %li 涅槃部類 10 | %li 大集部類 11 | %li 經集部類 12 | %li 密教部類 13 | %li 律部類 14 | %li 毘曇部類 15 | %li 中觀部類 16 | %li 瑜伽部類 17 | %li 論集部類 18 | %li 淨土宗部類 19 | %li 禪宗部類 20 | %li 史傳部類 21 | %li 事彙部類 22 | %li 敦煌寫本部類 23 | %li 國圖善本部類 24 | %li 漢譯南傳大藏經部類 25 | %li 新編部類 -------------------------------------------------------------------------------- /app/views/static_pages/category.haml: -------------------------------------------------------------------------------- 1 | %h1 category 參數 2 | 3 | %p 指定部類 4 | 5 | %p 例: #{ link_to_url '/kwic3?q=法鼓&category=阿含部類' } 6 | 7 | %p 可用部類名稱: 8 | 9 | %ul 10 | %li 本緣部類 11 | %li 阿含部類 12 | %li 般若部類 13 | %li 法華部類 14 | %li 華嚴部類 15 | %li 寶積部類 16 | %li 涅槃部類 17 | %li 大集部類 18 | %li 經集部類 19 | %li 密教部類 20 | %li 律部類 21 | %li 毘曇部類 22 | %li 中觀部類 23 | %li 瑜伽部類 24 | %li 論集部類 25 | %li 淨土宗部類 26 | %li 禪宗部類 27 | %li 史傳部類 28 | %li 事彙部類 29 | %li 敦煌寫本部類 30 | %li 國圖善本部類 31 | %li 南傳大藏經部類 32 | %li 新編部類 -------------------------------------------------------------------------------- /app/views/static_pages/chinese_tools.haml: -------------------------------------------------------------------------------- 1 | %h1 中文工具 2 | %ul 3 | %li= link_to '分詞簡易界面', controller: 'word_seg', action: 'index' 4 | %li= link_to '分詞 API', controller: 'static_pages', action: 'word_seg' 5 | %li= link_to '簡體轉繁體', controller: 'static_pages', action: 'sc2tc' 6 | -------------------------------------------------------------------------------- /app/views/static_pages/common_parameters.haml: -------------------------------------------------------------------------------- 1 | %h1 API 通用參數 2 | %ul 3 | %li= link_to "callback", controller: 'static_pages', action: 'callback' 4 | %li= link_to "category 部類", controller: 'static_pages', action: 'category' 5 | -------------------------------------------------------------------------------- /app/views/static_pages/creators.html.haml: -------------------------------------------------------------------------------- 1 | %h1 以作譯者搜尋 2 | 3 | %h2 以作譯者 ID 搜尋 4 | %p 5 | 例:#{link_to_url '/works?creator_id=A000439'} 6 | 7 | %h2 以作譯者姓名搜尋 8 | %p 不論是否已確認 ID,全部搜尋 9 | %p 10 | 例:#{link_to_url '/works?creator=竺'} 11 | 12 | %p 只搜尋尚未確認 ID 的資料 13 | %p 14 | 例:#{link_to_url '/works?creator_name=竺'} 15 | 16 | -------------------------------------------------------------------------------- /app/views/static_pages/download.haml: -------------------------------------------------------------------------------- 1 | %h1 Download 2 | %ul 3 | %li= link_to "HTML版 佛典", controller: 'static_pages', action: 'download_html' 4 | %li= link_to "純文字版 佛典", controller: 'static_pages', action: 'download_text' 5 | %li= link_to "DocuXml", controller: 'static_pages', action: 'download_docusky' 6 | %li= link_to "電子書", controller: 'static_pages', action: 'download_ebooks' 7 | %li= link_to "校注", controller: 'static_pages', action: 'download_footnotes' 8 | -------------------------------------------------------------------------------- /app/views/static_pages/download_docusky.haml: -------------------------------------------------------------------------------- 1 | %h1 下載 DocuXml 格式佛典 2 | 3 | %h2 一卷一檔 4 | %p 例: #{ link_to_url '/download/docusky/A1057_001.docusky.xml' } 5 | 6 | %h2 一部佛典一個檔 7 | %p 例: #{ link_to_url '/download/docusky/A1057.docusky.xml' } 8 | -------------------------------------------------------------------------------- /app/views/static_pages/download_footnotes.haml: -------------------------------------------------------------------------------- 1 | %h1 下載 校注 2 | %p 一卷一檔,CSV 格式,例如下載 T0001 長阿含經 第一卷的校注: 3 | %p= link_to_url '/download/footnotes/T/T0001/001.csv' 4 | -------------------------------------------------------------------------------- /app/views/static_pages/download_html.haml: -------------------------------------------------------------------------------- 1 | %h1 下載 HTML 格式佛典 2 | 3 | %h2 一卷一檔 4 | %p 例: #{ link_to_url '/download/html/A1057_001.html' } 5 | 6 | %h2 一部佛典一個 zip 檔 7 | %p 例: #{ link_to_url '/download/html/A1057.html.zip' } 8 | 9 | %h2 檔案內容 10 | %h3 缺字資訊 11 | %p 例: #{ link_to_url '/download/html/T0001_002.html.zip' } 12 | %p 檔案中有缺字資訊: <span class="gaiji" data-gid="CB02596">𥡳</span> -------------------------------------------------------------------------------- /app/views/static_pages/download_text.haml: -------------------------------------------------------------------------------- 1 | %h1 下載 純文字 格式佛典 2 | %ul 3 | %li= link_to('下載 全部', '#all') 4 | %li= link_to('下載 單部佛典', '#work') 5 | %li= link_to('下載 單卷', '#work') 6 | %li= link_to('悉曇字', '#siddam') 7 | %li= link_to('圖形', '#graphic') 8 | %li= link_to('表格', '#table') 9 | 10 | %h2#all 全部 CBETA 一個 zip 檔 11 | %ul 12 | %li 含校注: #{ link_to_url '/download/cbeta-text-with-notes.zip' } 13 | %li 不含校注: #{ link_to_url '/download/cbeta-text.zip' } 14 | 15 | %h2#work 一部佛典一個 zip 檔 16 | %ul 17 | %li 含校注: #{ link_to_url '/download/text-with-notes/T0001.txt.zip' } 18 | %li 不含校注: #{ link_to_url '/download/text/T0001.txt.zip' } 19 | %li 含目次,例如上述 zip 檔解壓縮後裡面有 T0001-toc.txt. 20 | 21 | %h2#juan 一卷一檔 22 | %ul 23 | %li 含校注: #{ link_to_url '/download/text-with-notes/T0001_001.txt.zip' } 24 | %li 不含校注: #{ link_to_url '/download/text/T0001_001.txt.zip' } 25 | 26 | %h2#siddam 悉曇字 27 | 28 | %p 以羅馬轉寫呈現,例: #{ link_to_url '/download/text/T0864A.txt.zip' } 29 | 30 | %h2#graphic 圖形 31 | 32 | %p 以【圖:T16p0845_01.gif】表示,圖檔也一起包含在 zip 檔裡。 33 | %p 例: #{ link_to_url '/download/text/T0719_001.txt.zip' } 34 | 35 | %h2#table 表格 36 | 37 | %p 逐列、逐欄 分行呈現,例: #{ link_to_url '/download/text/T2035_003.txt.zip' } 38 | %p ○四處十六會圖 39 | -------------------------------------------------------------------------------- /app/views/static_pages/editions.html.haml: -------------------------------------------------------------------------------- 1 | %h1 edition 參數說明 2 | %p 3 | 指定版本,預設為 CBETA。 4 | 5 | %h2 允許的值 6 | %ul 7 | %li CBETA 8 | %li 大 9 | %li 大→CB 10 | %li 大→unknown 11 | %li 大→丁 12 | %li 大→万 13 | %li 大→丙 14 | %li 大→中 15 | %li 大→久 16 | %li 大→乙 17 | %li 大→元 18 | %li 大→內 19 | %li 大→別 20 | %li 大→北藏 21 | %li 大→北藏-CB 22 | %li 大→卍續 23 | %li 大→南 24 | %li 大→南藏 25 | %li 大→博 26 | %li 大→原 27 | %li 大→和 28 | %li 大→嘉興 29 | %li 大→大曆 30 | %li 大→宋 31 | %li 大→宮 32 | %li 大→宮乙 33 | %li 大→己 34 | %li 大→德 35 | %li 大→戊 36 | %li 大→房山 37 | %li 大→敦 38 | %li 大→敦丙 39 | %li 大→敦乙 40 | %li 大→敦方 41 | %li 大→日光 42 | %li 大→明 43 | %li 大→明異 44 | %li 大→東 45 | %li 大→森 46 | %li 大→流布別本 47 | %li 大→流布本 48 | %li 大→流通本 49 | %li 大→獅谷 50 | %li 大→甲 51 | %li 大→知 52 | %li 大→石 53 | %li 大→磧 54 | %li 大→磧砂 55 | %li 大→福 56 | %li 大→福乙 57 | %li 大→縮 58 | %li 大→聖 59 | %li 大→聖丙 60 | %li 大→聖乙 61 | %li 大→補編 62 | %li 大→西 63 | %li 大→醍 64 | %li 大→金 65 | %li 大→高 66 | %li 大→麗 67 | %li 大→麗-CB 68 | %li 大→麗乙 69 | %li 大→龍 70 | %li 大→A 71 | %li 大→B -------------------------------------------------------------------------------- /app/views/static_pages/get_html.html.haml: -------------------------------------------------------------------------------- 1 | %h1 取得某卷 HTML 2 | %p 3 | HTML 內有各種標記供前端 UI 使用,參考 4 | = precede "〈" do 5 | = succeed "〉。" do 6 | =link_to('HTML for UI 格式說明', controller: "static_pages", action: "html_for_ui") 7 | 8 | %p 例如: 9 | %ul 10 | %li 取得 T0001 第1卷: #{link_to_url '/juans?work=T0001&juan=1'} 11 | 12 | %h2 參數 13 | %table.table 14 | %tr 15 | %td 參數名稱 16 | %td 說明 17 | %tr 18 | %td work_info 19 | %td 20 | %p 是否一併回傳「佛典資訊」 21 | %p 預設為 0: 不回傳 22 | %p 若設為 1: 回傳 23 | %p 例: #{link_to_url '/juans?work=T0001&juan=1&work_info=1'} 24 | %tr 25 | %td toc 26 | %td 27 | %p 是否一併回傳目次 28 | %p 預設為 0: 不回傳目次 29 | %p 若設為 1 則一併回傳目次 30 | %p 例: #{link_to_url '/juans?work=T0001&juan=1&toc=1'} 31 | 32 | %h2 回傳佛典資訊 33 | %pre 34 | :preserve 35 | { 36 | "num_found": 1, 37 | "results": [...], 38 | "work_info": {...} 39 | } 40 | 41 | %h2 回傳目次 42 | %pre 43 | :preserve 44 | { 45 | "num_found": 1, 46 | "results": [...], 47 | "toc": { 48 | "mulu": [...], 49 | "juan": [...] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/views/static_pages/report.haml: -------------------------------------------------------------------------------- 1 | %h1 統計報表 2 | %ul 3 | %li= link_to "全集成統計數字", controller: 'report', action: 'index' 4 | %li 5 | 存取紀錄 6 | %ul 7 | %li= link_to "日統計表", controller: 'report', action: 'daily' 8 | %li= link_to "URL 統計表", controller: 'report', action: 'url' 9 | %li= link_to "Referer 統計表", controller: 'report', action: 'referer' 10 | -------------------------------------------------------------------------------- /app/views/static_pages/sc2tc.haml: -------------------------------------------------------------------------------- 1 | %h1 中文簡體轉繁體 2 | %p 例: #{link_to_url '/chinese_tools/sc2tc?q=简体转繁体'} -------------------------------------------------------------------------------- /app/views/static_pages/scope_selector.haml: -------------------------------------------------------------------------------- 1 | %h1 範圍選擇清單 2 | 3 | %p 供前端做「範圍選擇」樹狀目錄使用。 4 | 5 | %ul 6 | %li=link_to '依部類選擇', controller: 'export', action: 'scope_selector_by_category' 7 | %li=link_to '依刊本選擇', controller: 'export', action: 'scope_selector_by_vol' 8 | %li=link_to '作譯者依筆劃', controller: 'export', action: 'creator_strokes' 9 | %li=link_to '作譯者依筆劃(含譯著)', controller: 'export', action: 'creator_strokes_works' 10 | %li=link_to '朝代期間佛典列表', controller: 'export', action: 'dynasty_works' 11 | -------------------------------------------------------------------------------- /app/views/static_pages/search_extended.haml: -------------------------------------------------------------------------------- 1 | %h1 擴充模式 全文檢索 2 | %p 3 | 例:#{link_to_url '/search/extended?q="法鼓"'} 4 | 5 | %p 請注意上面的雙引號不可省略。 6 | 7 | %p 以下範例均要做 URL encode, 例如: 8 | 9 | %pre "波羅蜜" | "波羅密" 10 | 11 | %p 要編碼為 12 | 13 | %pre %22波羅蜜%22%20%7C%20%22波羅密%22 14 | 15 | %h2 AND 16 | %p 多個字詞都必須出現。將每個詞用雙引號括起來,再以空格隔開多個字詞。 17 | %p 例:#{link_to_url '/search/extended?q="法鼓" "聖嚴"'} 18 | 19 | %h2 OR 20 | %pre "波羅蜜" | "波羅密" 21 | %p 例:#{link_to_url '/search/extended?q="波羅蜜" | "波羅密"'} 22 | 23 | %h2 NOT 24 | %p 例:#{link_to_url '/search/extended?q="迦葉" !"迦葉佛"'} 25 | 26 | %h2 NEAR 搜尋 27 | %p 28 | 例: 29 | =link_to_url '/search/all_in_one?q="法鼓" NEAR/7 "迦葉"' 30 | %p NEAR/ 後面的數字 表示兩個關鍵詞中間的距離 31 | 32 | %h2 參數 33 | %table.table 34 | %tr 35 | %td 參數名稱 36 | %td 37 | %td 說明 38 | =render partial: 'search-arg-paginate' 39 | -------------------------------------------------------------------------------- /app/views/static_pages/search_facet.haml: -------------------------------------------------------------------------------- 1 | %h1 Facet 2 | %h2 藏經編號 3 | %p 4 | 例:#{link_to_url '/search/facet/canon?q=法鼓'} 5 | 6 | %h2 部類 7 | %p 8 | 例:#{link_to_url '/search/facet/category?q=法鼓'} 9 | 10 | %p 回傳在各部類的符合卷數 11 | 12 | %h2 朝代 13 | %p 14 | 例:#{link_to_url '/search/facet/dynasty?q=法鼓'} 15 | 16 | %h2 作譯者 ID 17 | %p 18 | 例:#{link_to_url '/search/facet/creator?q=法鼓'} 19 | 20 | %h2 佛典編號 21 | %p 22 | 例:#{link_to_url '/search/facet/work?q=法鼓'} 23 | 24 | %h2 一次回傳五種 facet 25 | %p 26 | 不指定參數 f,例:#{link_to_url '/search/facet?q=法鼓'} 27 | %p 回傳資料是一個 hash: 28 | %pre 29 | :preserve 30 | { 31 | "canon": [...], 32 | "category": [...], 33 | "creator": [...], 34 | "dynasty": [...], 35 | "work": [...] 36 | } 37 | -------------------------------------------------------------------------------- /app/views/static_pages/search_index.haml: -------------------------------------------------------------------------------- 1 | %h1 Search 2 | %ul 3 | %li= link_to "經目搜尋", { controller: 'static_pages', action: 'search_toc' } 4 | %li= link_to "一般全文檢索", { controller: 'static_pages', action: 'search' } 5 | %li= link_to "擴充語法檢索", { controller: 'static_pages', action: 'search_extended' } 6 | %li= link_to "限制搜尋範圍", { controller: 'static_pages', action: 'search_filter' } 7 | %li= link_to "異體字", { controller: 'static_pages', action: 'search_vars' } 8 | %li= link_to "近義詞 (near synonyms)", { controller: 'static_pages', action: 'search_synonym' } 9 | %li= link_to "簡體字", { controller: 'static_pages', action: 'search_sc' } 10 | %li= link_to "Facet", { controller: 'static_pages', action: 'search_facet' } 11 | %li= link_to "All in One", { controller: 'static_pages', action: 'search_all_in_one' } 12 | %li= link_to "Notes", { controller: 'static_pages', action: 'search_notes' } 13 | %li= link_to "Title", { controller: 'static_pages', action: 'search_title' } 14 | %li= link_to "KWIC", { controller: 'static_pages', action: 'search_kwic' } 15 | %li= link_to "相似搜尋", { controller: 'static_pages', action: 'search_similar' } 16 | -------------------------------------------------------------------------------- /app/views/static_pages/search_sc.haml: -------------------------------------------------------------------------------- 1 | %h1 以簡體字搜尋 CBETA 2 | 3 | %p 使用 OpenCC 將簡體轉為繁體,再做搜尋,並回傳筆數。 4 | 5 | %p 例: #{link_to_url '/search/sc?q=四圣谛'} 6 | 7 | %p 如果繁簡相同,例如 q=上烏,則回傳: 8 | %pre 9 | :preserve 10 | { 11 | "q": "上烏", 12 | "hits": 0 13 | } 14 | 15 | %p 16 | =link_to "限制搜尋範圍", controller: "static_pages", action: "search_filter" 17 | 的參數也都可以使用。 18 | -------------------------------------------------------------------------------- /app/views/static_pages/search_synonym.haml: -------------------------------------------------------------------------------- 1 | %h1 近義詞 搜尋 2 | 3 | %p 例: #{link_to_url '/search/synonym?q=文殊師利'} 4 | -------------------------------------------------------------------------------- /app/views/static_pages/search_title.haml: -------------------------------------------------------------------------------- 1 | %h1 搜尋 佛典標題(經名) 2 | 3 | %p 例:#{link_to_url '/search/title?q=觀無量壽經'} 4 | 5 | %p 模糊搜尋,至少符合3個字。 6 | 7 | %h2 參數 8 | %table.table 9 | %tr 10 | %td 參數名稱 11 | %td 12 | %td 說明 13 | =render partial: 'search-arg-paginate' 14 | -------------------------------------------------------------------------------- /app/views/static_pages/search_vars.haml: -------------------------------------------------------------------------------- 1 | %h1 異體字查詢 2 | %p 3 | 列出可能的異體字變化,例:#{link_to_url '/search/variants?q=著衣持鉢'} 4 | 5 | %h2 資料來源 6 | %ul 7 | %li 8 | 開放資料: 9 | =link_to nil, 'https://github.com/DILA-edu/cbeta-metadata/tree/master/variants' 10 | 11 | %h2 參數 12 | %table.table 13 | %tr 14 | %td 參數名稱 15 | %td 16 | %td 說明 17 | %tr 18 | %td q 19 | %td 必須 20 | %td 要搜尋的字詞。 21 | %tr 22 | %td scope 23 | %td 選項 24 | %td 25 | 如果 scope=title,則僅列出存在於佛典題名中的異體字變化。例如: 26 | %br 27 | #{link_to_url '/search/variants?q=神咒&scope=title'} 28 | 。 29 | %br 30 | 前端可利用此功能,在搜尋經名時提供「異體字建議」。 31 | =render partial: 'arg-cache' 32 | 33 | %p 34 | 限制搜尋範圍的參數也都可以使用,參考: 35 | =link_to '限制搜尋範圍', controller: 'static_pages', action: 'search_filter' 36 | 37 | %h2 回傳範例 38 | %pre 39 | :preserve 40 | { 41 | "time": 0.085839963, 42 | "num_found": 3, 43 | "results": [ 44 | { 45 | "q": "着衣持鉢", 46 | "hits": 43 47 | }, 48 | { 49 | "q": "著衣持缽", 50 | "hits": 101 51 | }, 52 | { 53 | "q": "著衣持盋", 54 | "hits": 8 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /app/views/static_pages/time.html.haml: -------------------------------------------------------------------------------- 1 | %h1 以時間搜尋 2 | 3 | %h2 以朝代名稱搜尋 4 | %p 例如 5 | %ul 6 | %li 搜尋唐朝成立的佛典:#{link_to_url '/works?dynasty=唐'} 7 | %li 搜尋多個朝代:#{link_to_url '/works?dynasty=符秦,前秦'} 8 | 9 | %h2 以公元年範圍搜尋 10 | %p 例如,搜尋成立年代在公元 600年至700年之間的佛典:#{link_to_url '/works?time_start=600&time_end=700'} -------------------------------------------------------------------------------- /app/views/static_pages/toc.html.haml: -------------------------------------------------------------------------------- 1 | %h1 佛典內目次 2 | %p 3 | 例如取得 T0001 的目次: 4 | = link_to_url '/works/toc?work=T0001' 5 | 6 | %h2 回傳資料 7 | %table.table 8 | %tr 9 | %th 欄位名稱 10 | %th 說明 11 | %tr 12 | %td title 13 | %td 目次節點 標題 14 | %tr 15 | %td file 16 | %td 目次節點 所在 xml 檔 主檔名。 17 | %tr 18 | %td juan 19 | %td 目次節點 所在卷號。 20 | %tr 21 | %td lb 22 | %td 目次節點 所在 頁、欄、行。 23 | %tr 24 | %td type 25 | %td 例如 T0001 目次節點「1 分」,回傳 type 為「分」。 26 | %tr 27 | %td n 28 | %td 例如 T0001 目次節點「1 分」,回傳 n 為 1. 29 | %tr 30 | %td isFolder 31 | %td 預設值為 false,若為 true,表示有 children. 32 | %tr 33 | %td children 34 | %td 下層目次節點 35 | -------------------------------------------------------------------------------- /app/views/static_pages/word_count.html.haml: -------------------------------------------------------------------------------- 1 | %h1 字數統計 2 | %ul 3 | %li=link_to "字數統計規則", "https://bit.ly/3MMH1V8" 4 | %li=link_to '下載字數統計表', { controller: 'works', action: 'word_count' } 5 | 6 | %p 回傳 CSV 格式檔案,內容是各部典籍字數統計。例: 7 | %pre.ml-3 8 | work,cjk_chars,en_words,canon,category 9 | A1057,38830,0,A,事彙部類 10 | -------------------------------------------------------------------------------- /app/views/static_pages/word_seg.html.haml: -------------------------------------------------------------------------------- 1 | %h1 自動分詞 2 | %p HTTP 方法: GET, POST 3 | %p 請求 URL: #{ link_to_url '/word_seg2' } 4 | %p 例: #{ link_to_url '/word_seg2?payload=觀自在菩薩,行深般若波羅蜜多時。' } 5 | 6 | %h2 參數 7 | %table.table 8 | %tr 9 | %th 參數名稱 10 | %th 說明 11 | %tr 12 | %td payload 13 | %td 要對其進行自動分詞的文字 14 | 15 | %h2 回傳欄位 16 | %table.table 17 | %tr 18 | %th 欄位名稱 19 | %th 說明 20 | %tr 21 | %td segmented 22 | %td 分詞後結果 23 | %tr 24 | %td error 25 | %td 錯誤 -------------------------------------------------------------------------------- /app/views/static_pages/work_index.haml: -------------------------------------------------------------------------------- 1 | %h1 Work 2 | %ul 3 | %li= link_to '取得某部佛典的資訊', controller: 'static_pages', action: 'work' 4 | %li= link_to '佛典內目次', controller: 'static_pages', action: 'toc' 5 | %li= link_to '取得某卷 HTML', controller: 'static_pages', action: 'get_html' 6 | %li= link_to 'Go to', controller: 'static_pages', action: 'goto' 7 | %li= link_to '取得行號範圍文字', controller: 'static_pages', action: 'line' 8 | %li= link_to '字數統計', controller: 'static_pages', action: 'word_count' 9 | -------------------------------------------------------------------------------- /app/views/static_pages/works.html.haml: -------------------------------------------------------------------------------- 1 | %h1 佛典範圍搜尋 2 | %h2 指定冊數起迄 3 | %p 4 | 例如: 5 | =link_to_url '/works?canon=T&vol_start=1&vol_end=2' 6 | 7 | %p 參數: 8 | %table.table 9 | %tr 10 | %th 參數名稱 11 | %th 說明 12 | %tr 13 | %td canon 14 | %td 藏經 ID,例如 T 或 X。 15 | %tr 16 | %td vol_star 17 | %td 開始冊數 18 | %tr 19 | %td vol_end 20 | %td 結束冊數 21 | 22 | %h2 指定經號起迄 23 | %p 24 | 例如: 25 | =link_to_url '/works?canon=T&work_start=1&work_end=2' 26 | 27 | %p 參數: 28 | %table.table 29 | %tr 30 | %th 參數名稱 31 | %th 說明 32 | %tr 33 | %td canon 34 | %td 藏經 ID,例如 T 或 X。 35 | %tr 36 | %td work_start 37 | %td 開始經號 38 | %tr 39 | %td work_end 40 | %td 結束經號 -------------------------------------------------------------------------------- /app/views/textref/meta.csv: -------------------------------------------------------------------------------- 1 | Field,Value 2 | MetaURL,https://cbdata.dila.edu.tw/stable/textref/meta.csv 3 | DataURL,https://cbdata.dila.edu.tw/stable/textref/data.csv 4 | ShortName,CBETA 5 | LongName,CBETA 6 | ResourceTemplate,http://cbetaonline.dila.edu.tw/{primary_id} 7 | SchemaURL,http://ctext.org/static/textrefschema.csv 8 | -------------------------------------------------------------------------------- /app/views/word_seg/index.haml: -------------------------------------------------------------------------------- 1 | %h1 DILA 佛典自動分詞 測試版 2 | = form_tag do 3 | %p= label_tag(:t, "請貼上要分詞的文字:") 4 | = text_area_tag :t, nil, rows: 20, cols: 100 5 | %p= submit_tag("送出") 6 | %h3 說明 7 | %ul 8 | %li 不支援咒語。 9 | %li 使用半形斜線做為分詞區隔符號。 -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) 3 | gem "bundler" 4 | require "bundler" 5 | 6 | # Load Spring without loading other gems in the Gemfile, for speed. 7 | Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring| 8 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 9 | gem "spring", spring.version 10 | require "spring/binstub" 11 | rescue Gem::LoadError 12 | # Ignore when Spring is not installed. 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: cb_data_production 11 | -------------------------------------------------------------------------------- /config/category-id.json: -------------------------------------------------------------------------------- 1 | { 2 | "阿含部類" : 1, 3 | "本緣部類" : 2, 4 | "般若部類" : 3, 5 | "法華部類" : 4, 6 | "華嚴部類" : 5, 7 | "寶積部類" : 6, 8 | "涅槃部類" : 7, 9 | "大集部類" : 8, 10 | "經集部類" : 9, 11 | "密教部類" : 10, 12 | "律部類" : 11, 13 | "毘曇部類" : 12, 14 | "中觀部類" : 13, 15 | "瑜伽部類" : 14, 16 | "論集部類" : 15, 17 | "淨土宗部類" : 16, 18 | "禪宗部類" : 17, 19 | "史傳部類" : 18, 20 | "事彙部類" : 19, 21 | "敦煌寫本部類" : 20, 22 | "國圖善本部類" : 21, 23 | "漢譯南傳大藏經部類" : 22, 24 | "新編部類" : 23 25 | } -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | 09n/3GDylgHFjqnsi4sSquqCZFlEN704u1KH5HIV29xH/UnX2VjjzNEjpq/Zx3QzDUOQHMbbSmLewHUhbkvI41ZK+u6+P40qMYl5ukurZoO0/jZKjomi+E1NRKFwka18vJqv0/JPyY8JoHIOttD3ht3YajQQ/WtT3ihYw7N9Qy3JtrXpBS/Wnk4yO8Vtt2t376+3dJsxqbz1jDqH/5q4F6qteLuWNS8UL6sxGJ2stLQ4Ht7n4tCWphQsJVEQDuL7Hjy2VMenrW1CZxkjOI2JvjbVYYmi8elayzbKRD/ApkYw0XJQoyiWr3k/IeBqG+7pYr6AOrLCsxxANFUqBrFftUekCXefm9ELYdAPsPR/af+uFSvFMslNtsiJ12u3zGdvYIiUTgp3VptNzXyj2iTPLWd8WpENDgzz+j9S--Cztuz6ROFDR7TEMM--H8YXkOZnOi2t3JtR7cRkfQ== -------------------------------------------------------------------------------- /config/credentials/cn.yml.enc: -------------------------------------------------------------------------------- 1 | Ue5Pb6U5VTgAJwZ3q2mMqUr9hz3iLWbtrbX+GyP1Zgg9Ur5S7oj+HgTUp6TpAM247wlZfgBHQ+PJ1dXM8TdzizwbZF1C+LEldILBMFEHRVeijF1oFeM1Byiq2SRF3CzWUN2OIPefIBJ2TQAA4wVDecWSHjHBlxHQ+qlsiw/65ljE9BZ+qfRwNi4pm8a4H4W1QyIMEWPbXs3cEiqIjBna3Nj09QMw6upI21DRMW0HySwGbdpkxxJt+a5gYjyvyhvMar16q6oeK/Rn3hHzCnQB6Q==--Vitr4T5deoRYBvhC--0ZkKRZqDlGblsTwsA61LXg== 2 | -------------------------------------------------------------------------------- /config/deploy/cn.rb: -------------------------------------------------------------------------------- 1 | server 'cbetaonline.cn', user: 'ray', roles: %w{web} 2 | set :deploy_to, '/mnt/CBETAOnline/cbdata' 3 | -------------------------------------------------------------------------------- /config/deploy/production.rb: -------------------------------------------------------------------------------- 1 | server 'sakya.dila.edu.tw', user: 'ray', roles: %w{app db web} 2 | set :application, 'cbapi1' 3 | set :deploy_to, '/var/www/cbapi1' 4 | -------------------------------------------------------------------------------- /config/deploy/sakya.rb: -------------------------------------------------------------------------------- 1 | server 'sakya.dila.edu.tw', user: 'ray', roles: %w{app db web} 2 | set :deploy_to, '/var/www/cbapi1' -------------------------------------------------------------------------------- /config/deploy/staging.rb: -------------------------------------------------------------------------------- 1 | server 'sakya.dila.edu.tw', user: 'ray', roles: %w{app db web} 2 | set :application, 'cbapi2' 3 | set :deploy_to, '/var/www/cbapi2' 4 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w[ admin.js admin.css ] 13 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code 7 | # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". 8 | Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] 9 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap, inline scripts, and inline styles. 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src style-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. 4 | # Use this to limit dissemination of sensitive information. 5 | # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Once upgraded flip defaults one by one to migrate to the new default. 6 | # 7 | # Read the Rails 5.0 release notes for more info on each option. 8 | 9 | # Enable per-form CSRF tokens. Previous versions had false. 10 | Rails.application.config.action_controller.per_form_csrf_tokens = false 11 | 12 | # Enable origin-checking CSRF mitigation. Previous versions had false. 13 | Rails.application.config.action_controller.forgery_protection_origin_check = false 14 | 15 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 16 | # Previous versions had false. 17 | ActiveSupport.to_time_preserves_timezone = false 18 | 19 | # Require `belongs_to` associations by default. Previous versions had false. 20 | Rails.application.config.active_record.belongs_to_required_by_default = false 21 | 22 | # Do not halt callback chains when a callback returns false. Previous versions had true. 23 | #ActiveSupport.halt_callback_chains_on_return_false = true 24 | -------------------------------------------------------------------------------- /config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide HTTP permissions policy. For further 4 | # information see: https://developers.google.com/web/updates/2018/06/feature-policy 5 | 6 | # Rails.application.config.permissions_policy do |policy| 7 | # policy.camera :none 8 | # policy.gyroscope :none 9 | # policy.microphone :none 10 | # policy.usb :none 11 | # policy.fullscreen :self 12 | # policy.payment :self, "https://secure.example.com" 13 | # end 14 | -------------------------------------------------------------------------------- /config/initializers/rswag_ui.rb: -------------------------------------------------------------------------------- 1 | Rswag::Ui.configure do |c| 2 | 3 | # List the Swagger endpoints that you want to be documented through the 4 | # swagger-ui. The first parameter is the path (absolute or relative to the UI 5 | # host) to the corresponding endpoint and the second is a title that will be 6 | # displayed in the document selector. 7 | # NOTE: If you're using rspec-api to expose Swagger files 8 | # (under openapi_root) as JSON or YAML endpoints, then the list below should 9 | # correspond to the relative paths for those endpoints. 10 | 11 | case Rails.env 12 | when 'production' 13 | c.openapi_endpoint '/stable/api-docs/openapi.yaml', 'CBETA API Docs' 14 | when 'staging' 15 | c.openapi_endpoint '/dev/api-docs/openapi.yaml', 'CBETA API Docs' 16 | else 17 | c.openapi_endpoint "/api-docs/openapi.yaml?<%= Time.now.to_i %>", 'CBETA API Docs' 18 | end 19 | 20 | # Add Basic Auth in case your API is private 21 | # c.basic_auth_enabled = true 22 | # c.basic_auth_credentials 'username', 'password' 23 | end 24 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_cbdata13_session' 4 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | Spring.watch( 2 | ".ruby-version", 3 | ".rbenv-vars", 4 | "tmp/restart.txt", 5 | "tmp/caching-dev.txt" 6 | ) 7 | -------------------------------------------------------------------------------- /data-static/categories.json: -------------------------------------------------------------------------------- 1 | { 2 | "1": "阿含部類", 3 | "2": "本緣部類", 4 | "3": "般若部類", 5 | "4": "法華部類", 6 | "5": "華嚴部類", 7 | "6": "寶積部類", 8 | "7": "涅槃部類", 9 | "8": "大集部類", 10 | "9": "經集部類", 11 | "10": "密教部類", 12 | "11": "律部類", 13 | "12": "毘曇部類", 14 | "13": "中觀部類", 15 | "14": "瑜伽部類", 16 | "15": "論集部類", 17 | "16": "淨土宗部類", 18 | "17": "禪宗部類", 19 | "18": "史傳部類", 20 | "19": "事彙部類", 21 | "20": "敦煌寫本部類", 22 | "21": "國圖善本部類", 23 | "22": "南傳大藏經部類", 24 | "23": "新編部類" 25 | } -------------------------------------------------------------------------------- /data-static/dynasty-order.csv: -------------------------------------------------------------------------------- 1 | dynasty,time_from,time_to 2 | 漢,-202,220 3 | 西漢,-201,8 4 | 新,8,23 5 | 東漢,25,220 6 | 曹魏,220,265 7 | 蜀漢,221,263 8 | 吳,229,280 9 | 西晉,265,316 10 | 晉,265,420 11 | 東晉,317,420 12 | 前涼,301,387 13 | 前秦/符秦,351,394 14 | 後秦/姚秦,384,417 15 | 西秦/乞伏秦,385,431 16 | 北涼,397,460 17 | 南北朝,439,589 18 | 劉宋,420,479 19 | 元魏/北魏/後魏,386,534 20 | 東魏,534,550 21 | 西魏,535,557 22 | 蕭齊/南齊,479,502 23 | 梁/蕭梁,502,557 24 | 北齊/高齊,550,577 25 | 北周/宇文周,557,581 26 | 陳,557,589 27 | 隋,581,618 28 | 唐,618,907 29 | 武周,690,705 30 | 後梁/朱梁,907,923 31 | 後唐,923,936 32 | 後晉/石晉,936,947 33 | 後漢,947,951 34 | 後周,951,960 35 | 南唐,937,975 36 | 南漢,917,971 37 | 遼,907,1125 38 | 宋,960,1279 39 | 北宋,960,1127 40 | 南宋,1127,1279 41 | 夏/西夏,1032,1227 42 | 金,1115,1234 43 | 元,1271,1368 44 | 明,1368,1644 45 | 清,1644,1911 46 | 新羅,-56,936 47 | 高麗,918,1392 48 | 民國,1912,9999 49 | 日本,, 50 | unknown,, 51 | -------------------------------------------------------------------------------- /db/analytics_migrate/20201110030553_create_visits.rb: -------------------------------------------------------------------------------- 1 | class CreateVisits < ActiveRecord::Migration[6.0] 2 | def change 3 | create_table :visits do |t| 4 | t.string :url 5 | t.date :accessed_at 6 | t.integer :count 7 | t.index [:url, :accessed_at] 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/analytics_migrate/20220923035010_add_referer_to_visits.rb: -------------------------------------------------------------------------------- 1 | class AddRefererToVisits < ActiveRecord::Migration[6.0] 2 | def change 3 | add_column :visits, :referer, :string 4 | add_index :visits, [:url, :referer, :accessed_at] 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/analytics_schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.1].define(version: 2022_09_23_035010) do 14 | create_table "visits", force: :cascade do |t| 15 | t.string "url" 16 | t.date "accessed_at" 17 | t.integer "count" 18 | t.string "referer" 19 | t.index ["url", "accessed_at"], name: "index_visits_on_url_and_accessed_at" 20 | t.index ["url", "referer", "accessed_at"], name: "index_visits_on_url_and_referer_and_accessed_at" 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /db/migrate/20211215083341_add_lb_end_to_juanlines.rb: -------------------------------------------------------------------------------- 1 | class AddLbEndToJuanlines < ActiveRecord::Migration[6.0] 2 | def change 3 | add_column :juan_lines, :lb_end, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20221205031807_create_places.rb: -------------------------------------------------------------------------------- 1 | class CreatePlaces < ActiveRecord::Migration[6.0] 2 | def change 3 | def change 4 | remove_column :works, :place_name, :string 5 | remove_column :works, :place_id, :string 6 | remove_column :works, :place_long, :float 7 | remove_column :works, :place_lat, :float 8 | end 9 | 10 | create_table :places do |t| 11 | t.string :auth_id, index: { unique: true } 12 | t.string :name 13 | t.float :longitude 14 | t.float :latitude 15 | end 16 | 17 | create_join_table :places, :works 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /db/migrate/20230218080626_add_sort_to_catalog_entries.rb: -------------------------------------------------------------------------------- 1 | class AddSortToCatalogEntries < ActiveRecord::Migration[6.0] 2 | def change 3 | add_column :catalog_entries, :sort, :integer 4 | add_index :catalog_entries, [:parent, :sort] 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20230607054229_add_service_name_to_active_storage_blobs.active_storage.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from active_storage (originally 20190112182829) 2 | class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] 3 | def up 4 | return unless table_exists?(:active_storage_blobs) 5 | 6 | unless column_exists?(:active_storage_blobs, :service_name) 7 | add_column :active_storage_blobs, :service_name, :string 8 | 9 | if configured_service = ActiveStorage::Blob.service.name 10 | ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) 11 | end 12 | 13 | change_column :active_storage_blobs, :service_name, :string, null: false 14 | end 15 | end 16 | 17 | def down 18 | return unless table_exists?(:active_storage_blobs) 19 | 20 | remove_column :active_storage_blobs, :service_name 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /db/migrate/20240222014726_add_vol_to_lines.rb: -------------------------------------------------------------------------------- 1 | class AddVolToLines < ActiveRecord::Migration[6.1] 2 | def change 3 | change_table :lines do |t| 4 | t.string :work, :vol, :page, :col, :line 5 | t.integer :ser_no 6 | t.index :ser_no 7 | t.index [:vol, :page, :col, :line] 8 | t.index [:work, :juan, :ser_no] 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20240318074051_add_pua_to_gaijis.rb: -------------------------------------------------------------------------------- 1 | class AddPuaToGaijis < ActiveRecord::Migration[6.1] 2 | def change 3 | add_column :gaijis, :pua, :string 4 | add_index :gaijis, :pua 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20241112055713_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from active_storage (originally 20211119233751) 2 | class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0] 3 | def change 4 | return unless table_exists?(:active_storage_blobs) 5 | 6 | change_column_null(:active_storage_blobs, :checksum, true) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # CBETA API 工作流程 2 | 3 | ## 換新 Server 4 | 5 | 參考 apache2.md 6 | 7 | ## 測試版 新建 測試環境 (git branch: dev) 8 | 9 | 參考 staging.md 10 | 11 | ## 每季更新資料 12 | 13 | 參考 Quarterly.md 14 | 15 | ## 正式版上線 16 | 17 | 每季資料更新後,測試完成後上正式版。 18 | 19 | * fix bug 直接改正式版 (git branch: master) 20 | * merge 到 dev branch 21 | 22 | ## 移除舊版 23 | 24 | 參考 remove-old.md 25 | 26 | ## cn mirror 27 | 28 | 等正式版上線後再更新 cn mirror, 參考 cn.md. 29 | -------------------------------------------------------------------------------- /doc/apache2.md: -------------------------------------------------------------------------------- 1 | # Apache2 設定 2 | 3 | ## CORS 4 | 5 | 要讓其他開發者在不同 domain 也能使用 API. 6 | 7 | $ sudo a2enmod headers 8 | 9 | $ sudo editor /etc/apache2/sites-available/cbdata-le-ssl.conf 10 | 11 | 12 | ... 13 | Header set Access-Control-Allow-Origin "*" 14 | .. 15 | 16 | 17 | 測試語法 18 | $ sudo apachectl -t 19 | 20 | $ sudo service apache2 restart 21 | -------------------------------------------------------------------------------- /doc/cbeta-change-log.md: -------------------------------------------------------------------------------- 1 | # Create CBETA Change Log 2 | 3 | 參考 lib/tasks/quarterly/runbook-change-log.rb 4 | -------------------------------------------------------------------------------- /doc/cbeta-xml-p5a.md: -------------------------------------------------------------------------------- 1 | # 從 github 取得 cbeta xml p5a 2 | 3 | 第一次 clone 4 | 5 | cd ~/git-repos 6 | git clone git@github.com:cbeta-git/xml-p5a.git cbeta-xml-p5a 7 | 8 | 切換到某個版本,例如 2021 Q1: 9 | 10 | git checkout tags/2021Q1 11 | 12 | 如果要切換到某個 commit: 13 | 14 | git checkout 7c76cb2 15 | 16 | 如果要切換到最新的 commit: 17 | 18 | git checkout master 19 | 20 | 之後如果要更新 21 | 22 | cd ~/git-repos/cbeta-xml-p5a 23 | git pull 24 | -------------------------------------------------------------------------------- /doc/cn.md: -------------------------------------------------------------------------------- 1 | # cbetaonline.cn 2 | 3 | ## xml 更新特定 tag 4 | 5 | cd /mnt/CBETAOnline/git-repos/cbeta-xml-p5a 6 | git pull 7 | git checkout tags/2021Q1 8 | 9 | ## 半自動 runbook 10 | 11 | rake quarterly_cn 12 | 13 | ## 電子書 14 | 15 | curl -C - -O http://cbdata.dila.edu.tw/dev/download/cbeta-epub-2020q4.zip 16 | curl -C - -O http://cbdata.dila.edu.tw/dev/download/cbeta-mobi-2020q4.zip 17 | 18 | curl -C - -O http://cbdata.dila.edu.tw/dev/download/cbeta-pdf-2020q4-1.zip 19 | unzip cbeta-pdf-2020q4-1.zip 20 | 21 | curl -C - -O http://cbdata.dila.edu.tw/download/cbeta-pdf-2020q4-2.zip 22 | 23 | 續傳 24 | 25 | curl -C - -O [URL] 26 | 27 | curl Options 28 | 29 | -O, --remote-name Write output to a file named as the remote file 30 | -C, --continue-at OFFSET Resumed transfer OFFSET 31 | 32 | ## Sphinx 33 | 34 | sudo indexer --rotate cbeta7 35 | 36 | ## secret_key_base 37 | 38 | EDITOR="code --wait" bin/rails credentials:edit --environment cn 39 | 40 | 上面命令會做以下動作: 41 | 42 | * 建立 config/credentials/cn.key 如果沒有的話。這個檔不要送上 Git. 43 | * 建立 config/credentials/cn.yml.enc 沒果沒有的話。這個檔要送上 Git. 44 | * 解碼並使用編輯器 code 開啟 cn credentials 檔案。 45 | -------------------------------------------------------------------------------- /doc/deploy-rails-project.md: -------------------------------------------------------------------------------- 1 | # Deploy Rails Project 2 | 3 | 在 server 上建立 project folder 4 | 5 | mkdir /var/www/cbdata14 6 | chown ray:www-data /var/www/cbdata14 7 | 8 | 在 local 端 project root 下執行 9 | 10 | * 測試版: cap staging deploy 11 | * 正式版: cap production deploy 12 | 13 | ## 設定 secrets.yml 14 | 15 | 把 local 端的 config/secrets.yml 傳到 server 端 shared/config/secrets.yml 16 | 17 | 在 local 端執行 rake secret 得到一個新的 secret key 18 | 19 | 把這個新的 secret key 寫到 shared/config/secrets.yml 20 | 21 | production: 22 | secret_key_base: xxxxxxxxxx 23 | 24 | ## 設定 database.yml 25 | 26 | rails 根據 database.yml 來連上資料庫。下一步在 server 上的 project root 建立 shared/config/database.yml 27 | 28 | production: 29 | adapter: postgresql 30 | encoding: unicode 31 | database: cbdata13 32 | host: localhost 33 | pool: 5 34 | username: pg_cbdata 35 | password: 1234 36 | 37 | 上面的密碼 1234 要換成真正的密碼 38 | 39 | 在 local 端再次執行 40 | 41 | cap production deploy 42 | 43 | ## 設定 nginx 44 | 45 | 參考 nginx.md 46 | 47 | ## 清除舊 migration 48 | 49 | migration 資料夾裡的舊 migration 可以移除。 50 | 51 | 執行 `rake db:schema:load` 會根據 db/schema.rb 建立資料庫。 52 | 53 | 執行 `rake -T db` 可以查看有哪些 db tasks. 54 | -------------------------------------------------------------------------------- /doc/dev-mac.md: -------------------------------------------------------------------------------- 1 | # Mac 2 | 3 | ## mysql2 4 | 5 | $ brew info mysql 6 | Installed 7 | /opt/homebrew/Cellar/mysql/9.0.1 8 | 9 | $ gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/9.0.1 10 | 11 | 如果出現錯誤 12 | ld: library 'zstd' not found 13 | 執行 14 | $ gem install mysql2 -v '0.5.6' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib 15 | 16 | ## crf++ 17 | 18 | brew install crf++ 19 | -------------------------------------------------------------------------------- /doc/docx.md: -------------------------------------------------------------------------------- 1 | # xml for docx 2 | 3 | 1. xml4docx1 4 | 將 CBETA XML 簡化為適合 docx 使用 5 | rake 'convert:xml4docx1[2025-01,T]' 6 | 2. xml4docx2 7 | 將 xml4docx1 結果 做 扁平化 處理,如例:seg 包 seg 8 | rake 'convert:xml4docx2[T]' 9 | 3. check:xml4docx 10 | 檢查 xml4docx 正確性 11 | rake check:xml4docx 12 | -------------------------------------------------------------------------------- /doc/ebook.md: -------------------------------------------------------------------------------- 1 | # eBook 電子書 2 | 3 | 下載 heaven 做好的 PDF, MOBI 4 | 5 | * curl -C - -O https://archive.cbeta.org/download/pdf_a4/cbeta_pdf_1_2021q2.zip 6 | * curl -C - -O https://archive.cbeta.org/download/pdf_a4/cbeta_pdf_2_2021q2.zip 7 | * curl -C - -O https://archive.cbeta.org/download/pdf_a4/cbeta_pdf_3_2021q2.zip 8 | * curl -C - -O https://archive.cbeta.org/download/mobi/cbeta_mobi_2021q1.zip 9 | 10 | rename 11 | 12 | * mv cbeta_mobi_2021q2.zip cbeta-mobi-2021q2.zip 13 | * mv cbeta_pdf_1_2021q2.zip cbeta-pdf-2021q2-1.pdf 14 | * mv cbeta_pdf_2_2021q2.zip cbeta-pdf-2021q2-2.pdf 15 | * mv cbeta_pdf_3_2021q2.zip cbeta-pdf-2021q2-3.pdf 16 | 17 | unzip 18 | 19 | * unzip cbeta-mobi-2021q2.zip 20 | * unzip cbeta-pdf-2021q2-1.zip 21 | * unzip cbeta-pdf-2021q2-2.zip 22 | * unzip cbeta-pdf-2021q2-3.zip 23 | 24 | 清除 舊資料 25 | 26 | * rm -rf mobi 27 | * rm -rf pdf 28 | 29 | 合併 資料夾 30 | 31 | * mv cbeta_mobi_2021q2 mobi 32 | * mv cbeta_pdf_1_2021q2 pdf 33 | * mv cbeta_pdf_2_2021q2/* pdf 34 | * mv cbeta_pdf_3_2021q2/* pdf 35 | * rm -r cbeta_pdf_2_2021q2 36 | * rm -r cbeta_pdf_3_2021q2 37 | -------------------------------------------------------------------------------- /doc/https.md: -------------------------------------------------------------------------------- 1 | # HTTPS 2 | 3 | ## Firewall 允許 SSH 4 | 5 | sudo ufw allow OpenSSH 6 | 7 | ## Install Certbot 8 | 9 | 參考 [certbot instructions](https://certbot.eff.org/instructions) 10 | 11 | Ensure that your version of snapd is up to date 12 | 13 | sudo snap install core; sudo snap refresh core 14 | 15 | Remove certbot-auto and any Certbot OS packages 16 | 17 | sudo apt-get remove certbot 18 | 19 | Install Certbot 20 | 21 | sudo snap install --classic certbot 22 | 23 | Prepare the Certbot command 24 | 25 | sudo ln -s /snap/bin/certbot /usr/bin/certbot 26 | 27 | get and install your certificates 28 | 29 | sudo certbot --apache 30 | 31 | 應該要出現成功訊息: 32 | Your existing certificate has been successfully renewed, and the new certificate 33 | has been installed. 34 | 35 | Test automatic renewal 36 | 37 | sudo certbot renew --dry-run 38 | -------------------------------------------------------------------------------- /doc/import-layers.md: -------------------------------------------------------------------------------- 1 | # Import Layers 2 | 3 | ## 佛寺志專案 產生 layers 中介檔 4 | 5 | fosizhi/ruby/export.rb 6 | 產生 csv 檔放到 data/layers/fosizhi 7 | 8 | ## 要先產生 HTML 9 | 10 | rake convert:x2h[2018-12,GA] 11 | 12 | ## 匯入 layers 13 | 14 | 在 HTML 檔 插入 人名、地名 標記 15 | 16 | rake import:layers 17 | 18 | 上述命令會輸出檔案到 data/html-with-layers 19 | -------------------------------------------------------------------------------- /doc/juan-line.md: -------------------------------------------------------------------------------- 1 | # juan-line 2 | 3 | 先將資料準備在 data/juan-line, 如果資料有更新,可執行以下命令產生新資料: 4 | 5 | rake convert:juanline 6 | 7 | 或直接從舊版複製 8 | 9 | cp -r /var/www/cbdata6/shared/data/juan-line /var/www/cbdata7/shared/data 10 | 11 | 然後執行以下命令將資料匯入 RDB: 12 | 13 | rake import:juanline 14 | -------------------------------------------------------------------------------- /doc/kwic.md: -------------------------------------------------------------------------------- 1 | # KWIC 2 | 3 | ## 執行步驟 4 | 5 | rake kwic:x2h 6 | rake kwic:h2t # 約 9.5 hrs 7 | rake kwic:sa # 約 9.5 hrs 8 | rake kwic:sort_info 9 | rake kwic:rotate 10 | 11 | ## clear cache 12 | 13 | kwic 所需的全部純文字檔,為了加速,存在 server cache 裡, 14 | 這些 cache 要記得更新。 15 | 16 | run the following command in console 17 | 18 | Rails.cache.clear 19 | 20 | This will clear the cache from whatever cache store you are using 21 | -------------------------------------------------------------------------------- /doc/mirror.md: -------------------------------------------------------------------------------- 1 | # mirror site 所需磁碟空間 2 | 3 | 一套 約 24 GB 4 | 5 | * Rails 程式及各種格式資料:15 GB 6 | * PostgreSQL Database: 6 GB 7 | * CBETA XML: 2.2 GB 8 | * Sphinx Index (含標點):419 MB 9 | * Sphinx Index: 383 MB 10 | * CBETA 缺字資料: 44 MB 11 | * CBETA Metadata: 22 MB 12 | 13 | 兩套 48 GB 14 | 15 | 以上統計不含: 16 | * kwic 一套約 63 GB 17 | * dia.dila.edu.tw 圖檔 約 431 GB (佛寺志、大正藏、嘉興藏) 18 | 19 | ## 查看 PostgreSQL database size 20 | 21 | $ sudo su - postgres 22 | $ psql 23 | SELECT pg_database.datname, 24 | pg_size_pretty(pg_database_size(pg_database.datname)) AS size 25 | FROM pg_database; 26 | 27 | ## 查看 Sphinx Index Size 28 | 29 | $ cd /var/lib/sphinxsearch 30 | $ du -hs data7 31 | $ du -hs data7-puncs -------------------------------------------------------------------------------- /doc/new-rails-project.md: -------------------------------------------------------------------------------- 1 | # New Rails Project 2 | 3 | ## 複製 rails project folder 4 | 5 | 複製整個 rails project, 例如將 cbdata8 複製為 cbdata9 6 | 7 | 刪除 .git 資料夾 8 | 9 | ## rename rails project 10 | 11 | 必須做的 12 | 13 | * 修改 config/application.rb 裡的 14 | * module 名稱 15 | * 修改 config/deploy.rb 16 | 17 | 可做可不做的 18 | 19 | * 修改 config/initializers/session_store.rb 裡的 session 名稱 20 | 21 | ## 考慮是否更新 ruby 及 rails 的版本 22 | 23 | 參考 rails.md 24 | -------------------------------------------------------------------------------- /doc/nginx.md: -------------------------------------------------------------------------------- 1 | # Nginx 2 | 3 | ## config 4 | 5 | 編輯 /etc/nginx/sites-available/cbdata.dila 6 | 7 | location ~ ^/dev(/.*|$) { 8 | alias /var/www/cbdata13/current/public$1; # <-- be sure to point to 'public'! 9 | passenger_base_uri /dev; 10 | passenger_app_root /var/www/cbdata13/current; 11 | passenger_document_root /var/www/cbdata13/current/public; 12 | passenger_enabled on; 13 | passenger_ruby /home/ray/.rvm/gems/ruby-2.7.2@cbdata13/wrappers/ruby; 14 | gzip on; 15 | gzip_min_length 1k; 16 | gzip_types text/plain text/javascript application/javascript; 17 | } 18 | 19 | 執行以下命令可以得知 passenger_ruby 路徑: 20 | cd /var/www/cbdata14/current 21 | passenger-config --ruby-command 22 | 23 | ## 測試版、正式版 指向同一個 rails project 24 | 25 | 參考 Passenger 的 參數 passenger_app_group_name 說明: 26 | 27 | 28 | ## 重新啟動 nginx 29 | 30 | sudo service nginx restart 31 | 32 | 測試連結 33 | -------------------------------------------------------------------------------- /doc/prepare-files.md: -------------------------------------------------------------------------------- 1 | # Prepare Data Files 2 | 3 | ## Help HTML Files 4 | 5 | 由 server 上的舊版複製 6 | 7 | cp -r /var/www/cbdata10/shared/public/help /var/www/cbdata11/shared/public 8 | 9 | ## figures 10 | 11 | ### cn 12 | 13 | ln -s /mnt/CBETAOnline/git-repos/CBR2X-figures /mnt/CBETAOnline/cbdata/shared/data/figures 14 | 15 | ## places.json 16 | 17 | 由 server 上的舊版複製 data/places.json 18 | 19 | ## juan-line 20 | 21 | 由 server 上的舊版複製 shared/data/juan-line 22 | 23 | 如果資料有更新,可使用這裡的程式產生新資料 24 | /Users/ray/Documents/Projects/CBETA/juanline/bin/juanline.rb 25 | 26 | ## UUID 27 | 28 | 如果有新增佛典,要產生 UUID,參考 uuid.md 29 | 30 | ## 自動分詞 31 | 32 | data/crf-model/all 33 | -------------------------------------------------------------------------------- /doc/remove-old.md: -------------------------------------------------------------------------------- 1 | # Remove Old Version 2 | 3 | ## PostgreSQL 4 | 5 | 執行 psql 6 | 7 | sudo su - postgres 8 | psql 9 | 10 | list all database 11 | 12 | \l 13 | 14 | 移除舊 database 15 | 16 | drop database xxx; 17 | 18 | list all user 19 | 20 | \du 21 | 22 | 移除舊 user 23 | 24 | drop user pg_xxx; 25 | 26 | ## Ubuntu 27 | 28 | 刪除 舊版 server account 29 | 30 | sudo deluser --remove-home [UserName] 31 | -------------------------------------------------------------------------------- /doc/rvm.md: -------------------------------------------------------------------------------- 1 | # upgrade 2 | 3 | $ \curl -sSL https://get.rvm.io | sudo bash -s stable -------------------------------------------------------------------------------- /doc/sphinx-mac.md: -------------------------------------------------------------------------------- 1 | # Install Sphinx for Mac 2 | 3 | 查看 sphinx 版本 4 | brew info sphinx 5 | 6 | 安裝 sphinx 7 | brew install sphinx 8 | 9 | 上面命令會連同 mysql 一起安裝. 10 | 11 | ## sphinx configuration for Mac 12 | 13 | /Users/ray/Documents/Projects/CBETAOnline/sphinx/sphinx.conf 14 | 15 | ## Build Index 16 | 17 | 詳見: sphinx-build-index.md 18 | 19 | ## Application Config 20 | 21 | 設定使用哪一個 index, 編輯 config/environments/development.rb 22 | 23 | config.sphinx_index = 'cbeta' 24 | 25 | ## Start Search Engine 26 | 27 | cd /Users/ray/Documents/Projects/CBETAOnline/sphinx 28 | brew services start mysql 29 | searchd 30 | 31 | 如果沒有啟動 search engine, 會出現如下錯誤訊息: 32 | 33 | Can't connect to MySQL server 34 | 35 | ## MySQL Command Line 36 | 37 | mysql -h0 -P9306 38 | 39 | 如果出現 `command not found: mysql` 40 | 那要編輯 ~/.zshrc 41 | 42 | export PATH="/usr/local/opt/mysql@5.7/bin:$PATH" 43 | -------------------------------------------------------------------------------- /doc/sphinx.md: -------------------------------------------------------------------------------- 1 | # Sphinx Search 2 | 3 | 環境: Ubuntu 20.04.1 LTS 4 | 5 | ## Install 6 | 7 | $ sudo apt-get update 8 | $ sudo apt-get install sphinxsearch 9 | $ searchd 10 | 11 | 可以看到版本是 Sphinx 2.2.11 12 | 13 | ## sphinx configuration 14 | 15 | 如果欄位有變更,要修改 /etc/sphinxsearc 裡的下列檔案: 16 | 17 | * sphinx.conf 18 | * cbdata1.conf 19 | * titles1.conf 20 | * footnotes1.conf 21 | 22 | 建立 index 存放資料夾 23 | cd /var/lib/sphinxsearch 24 | mkdir data1 25 | mkdir data1-titles 26 | mkdir data1-footnotes 27 | 28 | ## 設定開機執行 29 | 30 | 編輯 /etc/default/sphinxsearch 31 | 32 | START=yes 33 | 34 | ## Build Index 35 | 36 | 詳見: sphinx-build-index.md 37 | 38 | ## Application Config 39 | 40 | 設定使用哪一個 index, 編輯 config/environments/production.rb 41 | 42 | config.sphinx_index = "cbeta#{config.cb.v}" 43 | config.x.sphinx_notes = "notes#{config.cb.v}" 44 | config.x.sphinx_titles = "titles#{config.cb.v}" 45 | 46 | ## MySQL Command Line 47 | 48 | mysql -h0 -P9306 49 | 50 | ## 清除舊版 Index 51 | 52 | /var/lib/sphinxsearch 53 | 54 | 注意 /var/lib/sphinxsearch/data 不能刪。 55 | -------------------------------------------------------------------------------- /doc/trouble-shooting.md: -------------------------------------------------------------------------------- 1 | # Passenger 2 | 3 | passenger-status 命令可以查看狀態 4 | 5 | ## Memory 6 | 7 | 如果某個 process 佔用太多 memory, 可以將它移除 8 | 9 | kill 10 | 11 | 企業版 Passenger 可以設定 PassengerMemoryLimit 欄位。 12 | 13 | ## 檢視 active requests 14 | 15 | sudo passenger-status --show=requests 16 | 17 | 注意 started_at 欄位,如果某個 request 已經執行超過 30秒,那可能就是有問題了。 18 | 19 | 企業版 Passenger 可以設定 PassengerMaxRequestTime -------------------------------------------------------------------------------- /doc/update-github.md: -------------------------------------------------------------------------------- 1 | # 更新、取得 Github Repositories 2 | 3 | ## cbeta xml p5a 4 | 5 | 參考 cbeta-xml-p5a.md 6 | 7 | ## cbeta 缺字資料 8 | 9 | git@github.com:cbeta-org/cbeta_gaiji.git 10 | 11 | ## 如果有 新增藏經 ID 或 新加入的佛典 12 | 13 | 參考 new-canon.md 14 | 15 | ## cbeta metadata 16 | 17 | production server 要有 cbeta metadata 18 | 19 | 如果是第一次取得 20 | 21 | cd ~/git-repos 22 | git clone git@github.com:DILA-edu/cbeta-metadata.git 23 | 24 | 如果是之後要取得更新 25 | 26 | cd /home/ray/git-repos/cbeta-metadata 27 | git pull 28 | -------------------------------------------------------------------------------- /doc/uuid.md: -------------------------------------------------------------------------------- 1 | # UUID 2 | 3 | 供 Asia Network 使用 4 | Resource Provider API 說明: 5 | 6 | 1. 先準備好 data/juan-line 7 | 8 | bundle exec rake convert:juanline 9 | 10 | 上面的 juan-line 在產生各卷的 UUID 時要用到。 11 | 12 | 2. 產生 UUID, 在 local 端執行 13 | 14 | bundle exec rake import:work_info 15 | bundle exec rake create:uuid 16 | 17 | 以上命令會產生 JSON 格式的 uuid 放在 data-static/uuid 資料夾裡 18 | 之前產生過的,會維持舊的。 19 | 20 | UUID 應該儘量維持不變,第一次產生之後就沿用。 21 | 22 | data-static 資料夾也要上傳 git. 23 | -------------------------------------------------------------------------------- /doc/variants.md: -------------------------------------------------------------------------------- 1 | # 異體字 2 | 3 | ## 由 CBETA 缺字庫 更新 異體字 到 metadata 4 | 5 | * update cbeta_gaiji from GitHub 6 | * 根據 說明 產生 vars-for-cbdata.json 7 | * 將 vars-for-cbdata.json 更新到 8 | 9 | ## 匯入 10 | 11 | 1. Update metatada from GitHub. 12 | 2. 啟動 sphinx 13 | 3. 由 cbeta-metadata/variants/variants.txt 匯入資料到 model: Variant,執行 14 | 15 | bundle exec rake import:vars 16 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/lib/tasks/.keep -------------------------------------------------------------------------------- /lib/tasks/README.md: -------------------------------------------------------------------------------- 1 | # Tasks 2 | 3 | ## 匯入佛典資訊 4 | 5 | 包含作譯者資料 6 | rake import:work_info 7 | -------------------------------------------------------------------------------- /lib/tasks/cbeta-module.rb: -------------------------------------------------------------------------------- 1 | module CBETAModule 2 | def cb_xml_updated_at(path: nil) 3 | path = path || "#{@canon}/#{@vol}/#{@sutra_no}.xml" 4 | t = @git.log.path(path).first 5 | abort "取得 git log 發生錯誤, path: #{path}" if t.nil? 6 | t.date.strftime('%Y-%m-%d') 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/tasks/check.rake: -------------------------------------------------------------------------------- 1 | namespace :check do 2 | 3 | desc "檢查電子書封面是否都存在" 4 | task :authority => :environment do 5 | require "tasks/check_authority" 6 | CheckAuthority.new.check 7 | end 8 | 9 | desc "檢查電子書封面是否都存在" 10 | task :covers => :environment do 11 | require "tasks/check_covers" 12 | CheckCover.new.check 13 | end 14 | 15 | desc "檢查 xml p5a 裡的缺字是否在 cbeta gem 之中都有缺字資訊" 16 | task :gaiji => :environment do 17 | require "tasks/check_gaiji" 18 | CheckGaiji.new.check 19 | end 20 | 21 | task :metadata => :environment do 22 | require "tasks/check_metadata" 23 | CheckMetadata.new.check 24 | end 25 | 26 | desc "檢查 CBETA xml p5a" 27 | task :p5a => :environment do 28 | CBETA::P5aChecker.new( 29 | xml_root: Rails.configuration.cbeta_xml, 30 | figures: Rails.configuration.x.figures, 31 | log: Rails.root.join('log', 'check_p5a.log') 32 | ).check 33 | end 34 | 35 | task :xml4docx do 36 | require 'tasks/xml4docx3' 37 | dir = Rails.root.join('data', 'xml4docx2') 38 | XMLForDocx3.new.check(dir) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/tasks/check_authority.rb: -------------------------------------------------------------------------------- 1 | require_relative 'cbeta_p5a_share' 2 | 3 | class CheckAuthority 4 | 5 | def initialize 6 | @authority = AuthorityService.new 7 | @authority.read_catalog 8 | @authority.read_persons 9 | end 10 | 11 | def check 12 | @errors = '' 13 | 14 | @authority.catalog.each do |work_id, work| 15 | next unless work.key?('contributors') 16 | work['contributors'].each do |contributor| 17 | id = contributor['id'] 18 | next if id.nil? 19 | unless @authority.persons.key?(id) 20 | @errors << "Catalog Authority #{work_id} contributor id #{id} 在 Person Authority 中不存在\n" 21 | end 22 | end 23 | end 24 | 25 | if @errors.empty? 26 | puts "檢查 Authority 成功,無錯誤。".green 27 | else 28 | puts @errors.red 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/tasks/check_covers.rb: -------------------------------------------------------------------------------- 1 | require_relative 'cbeta_p5a_share' 2 | 3 | class CheckCover 4 | 5 | def initialize 6 | @xml = Rails.application.config.cbeta_xml 7 | @base = File.join(Rails.configuration.cb.git, 'ebook-covers') 8 | end 9 | 10 | def check 11 | @errors = '' 12 | 13 | each_canon(@xml) do |canon| 14 | check_canon(canon) 15 | end 16 | 17 | if @errors.empty? 18 | puts "檢查 ebook 封面成功,無錯誤。".green 19 | else 20 | puts @errors.red 21 | end 22 | end 23 | 24 | private 25 | 26 | def check_canon(canon) 27 | src = File.join(@xml, canon) 28 | Dir["#{src}/**/*.xml"].sort.each do |fn| 29 | bn = File.basename(fn) 30 | $stderr.puts "check ebook cover: #{bn}" 31 | work = CBETA.get_work_id_from_file_basename(bn) 32 | cover = File.join(@base, canon, "#{work}.jpg") 33 | unless File.exist?(cover) 34 | @errors << "#{bn} #{cover} 不存在\n" 35 | end 36 | end 37 | end 38 | 39 | include CbetaP5aShare 40 | end 41 | -------------------------------------------------------------------------------- /lib/tasks/check_gaiji.rb: -------------------------------------------------------------------------------- 1 | require_relative 'cbeta_p5a_share' 2 | 3 | class CheckGaiji 4 | 5 | def initialize 6 | @xml_root = Rails.application.config.cbeta_xml 7 | @gaiji = CBETA::Gaiji.new 8 | end 9 | 10 | def check 11 | @errors = '' 12 | 13 | each_canon(@xml_root) do |c| 14 | check_canon(c) 15 | end 16 | 17 | puts @errors 18 | end 19 | 20 | private 21 | 22 | def check_canon(canon) 23 | src = File.join(@xml_root, canon) 24 | Dir["#{src}/**/*.xml"].sort.each do |fn| 25 | basename = File.basename(fn) 26 | print "\rcheck gaiji: #{basename} " 27 | doc = File.open(fn) { |f| Nokogiri::XML(f) } 28 | doc.remove_namespaces! 29 | doc.search('g').each do |e| 30 | gid = e['ref'][1..-1] 31 | if @gaiji.key? gid 32 | g = @gaiji[gid] 33 | if gid.start_with? 'CB' 34 | @errors << "#{basename} 缺組字式:#{gid}\n" if g['composition'].blank? 35 | end 36 | else 37 | @errors << "#{basename} #{gid} 不存在\n" 38 | end 39 | end 40 | end 41 | puts 42 | end 43 | 44 | include CbetaP5aShare 45 | end 46 | -------------------------------------------------------------------------------- /lib/tasks/check_metadata.rb: -------------------------------------------------------------------------------- 1 | class CheckMetadata 2 | def check 3 | $stderr.puts "check metadata" 4 | @titles = read_titles 5 | src = Rails.configuration.cbeta_xml 6 | errors = [] 7 | Dir["#{src}/**/*.xml"].sort.each do |fn| 8 | bn = File.basename(fn, '.*') 9 | id = CBETA.get_work_id_from_file_basename(bn) 10 | unless @titles.key? id 11 | errors << bn 12 | end 13 | end 14 | if errors.empty? 15 | puts "檢查通過,未發現錯誤。".green 16 | else 17 | puts "以下佛典缺 title:".red 18 | puts errors.join(', ') 19 | end 20 | errors.empty? 21 | end 22 | 23 | private 24 | 25 | def read_titles 26 | src = Rails.configuration.x.work_info 27 | r = {} 28 | Dir.glob("#{src}/*.json") do |f| 29 | works = JSON.load_file(f) 30 | works.each do |id, h| 31 | r[id] = h['title'] 32 | end 33 | end 34 | r 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /lib/tasks/convert_docusky.rb: -------------------------------------------------------------------------------- 1 | require 'chronic_duration' 2 | require_relative 'x2x_for_docusky' 3 | 4 | class ConvertDocusky 5 | 6 | def convert(canon) 7 | t1 = Time.now 8 | xml_root = Rails.application.config.cbeta_xml 9 | 10 | tmpdir = Rails.root.join('data', 'docusky-tmp') 11 | 12 | c = P5aToDocusky.new(xml_root, tmpdir) 13 | c.convert(canon) 14 | 15 | src = tmpdir 16 | dest = Rails.root.join('data', 'download', 'docusky') 17 | FileUtils.mkdir_p(dest) 18 | 19 | # 備份舊資料 20 | if Dir.exist? dest 21 | bak = dest.to_s + '-' + Time.new.strftime("%Y-%m-%d-%H%M%S") 22 | puts "move #{dest} => #{bak}" 23 | FileUtils.mv dest, bak 24 | end 25 | 26 | puts "move #{src} => #{dest}" 27 | FileUtils.mv src, dest 28 | 29 | puts "花費時間:" + ChronicDuration.output(Time.now - t1) 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /lib/tasks/convert_x2h_for_download.rb: -------------------------------------------------------------------------------- 1 | require 'chronic_duration' 2 | require_relative 'x2h_for_download' 3 | 4 | class ConvertX2hForDownload 5 | 6 | def convert(publish, canon) 7 | t1 = Time.now 8 | xml_root = Rails.application.config.cbeta_xml 9 | 10 | tmpdir = Rails.root.join('data', 'html-for-download-tmp') 11 | 12 | x2h = P5aToHTMLForDownload.new(publish, xml_root, tmpdir) 13 | x2h.convert(canon) 14 | 15 | src = tmpdir 16 | dest = Rails.root.join('data', 'download', 'html') 17 | FileUtils.mkdir_p(dest) 18 | 19 | # 備份舊資料 20 | if Dir.exist? dest 21 | bak = dest.to_s + '-' + Time.new.strftime("%Y-%m-%d-%H%M%S") 22 | puts "move #{dest} => #{bak}" 23 | FileUtils.mv dest, bak 24 | end 25 | 26 | puts "move #{src} => #{dest}" 27 | FileUtils.mv src, dest 28 | 29 | puts "花費時間:" + ChronicDuration.output(Time.now - t1) 30 | end 31 | 32 | end 33 | -------------------------------------------------------------------------------- /lib/tasks/convert_x2t_for_download.rb: -------------------------------------------------------------------------------- 1 | require 'chronic_duration' 2 | require_relative 'x2t_for_download' 3 | 4 | class ConvertX2tForDownload 5 | 6 | def convert(publish, canon) 7 | t1 = Time.now 8 | 9 | tmpdir = Rails.root.join('data', 'text-for-download-tmp') 10 | args = { 11 | format: 'text', 12 | notes: false, # 不含校注 13 | publish: publish, 14 | xml_root: Rails.application.config.cbeta_xml, 15 | out_root: tmpdir, 16 | out2: Rails.root.join('data', 'download', 'text-for-asia-network') 17 | } 18 | x2t = P5aToTextForDownload.new(args) 19 | x2t.convert(canon) 20 | 21 | src = tmpdir 22 | dest = Rails.root.join('data', 'download', 'text') 23 | FileUtils.mkdir_p(dest) 24 | 25 | # 備份舊資料 26 | if Dir.exist? dest 27 | bak = dest.to_s + '-' + Time.new.strftime("%Y-%m-%d-%H%M%S") 28 | puts "move #{dest} => #{bak}" 29 | FileUtils.mv dest, bak 30 | end 31 | 32 | puts "move #{src} => #{dest}" 33 | FileUtils.mv src, dest 34 | 35 | puts "花費時間:" + ChronicDuration.output(Time.now - t1) 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /lib/tasks/convert_xml4docx.rb: -------------------------------------------------------------------------------- 1 | require 'chronic_duration' 2 | require_relative 'xml4docx1' 3 | require_relative 'xml4docx2' 4 | require_relative 'xml4docx3' 5 | 6 | class XMLForDocx 7 | def convert(publish, canon) 8 | t1 = Time.now 9 | xml_root = Rails.application.config.cbeta_xml 10 | 11 | dest1 = Rails.root.join('data', 'xml4docx1') 12 | 13 | c = XMLForDocx1.new(xml_root, dest1) 14 | args = { publish:, canon: } 15 | c.convert(args) 16 | 17 | dest2 = Rails.root.join('data', 'xml4docx2') 18 | XMLForDocx2.new.convert(dest1, dest2) 19 | 20 | XMLForDocx3.new.check(dest2) 21 | 22 | puts "花費時間:" + ChronicDuration.output(Time.now - t1) 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /lib/tasks/create.rake: -------------------------------------------------------------------------------- 1 | namespace :create do 2 | 3 | desc "產生 含別名的 作譯者清單" 4 | task :creators => :environment do 5 | require "tasks/create_creators" 6 | c = CreateCreatorsList.new 7 | c.create 8 | end 9 | 10 | desc "產生 UUID" 11 | task :uuid => :environment do 12 | require "tasks/create_uuid" 13 | c = CreateUuid.new 14 | c.create 15 | end 16 | end -------------------------------------------------------------------------------- /lib/tasks/css_parser.rb: -------------------------------------------------------------------------------- 1 | class CSSParser 2 | def initialize(str) 3 | a = str.split(';') 4 | @hash = {} 5 | a.each do |s| 6 | k, v = s.split(':') 7 | @hash[k.strip] = v.strip 8 | end 9 | end 10 | 11 | def ==(other) 12 | @hash == other.hash 13 | end 14 | 15 | def to_class 16 | if @hash.keys.size == 1 17 | case @hash.keys.first 18 | when "margin-left" 19 | i = @hash["margin-left"].delete_suffix("em").to_i 20 | "m#{i}" 21 | when "text-indent" 22 | i = @hash["text-indent"].delete_suffix("em").to_i 23 | if i >= 0 24 | "i#{i}" 25 | else 26 | "j#{-i}" 27 | end 28 | end 29 | elsif @hash.keys.size == 2 and @hash.key?("margin-left") and @hash.key?("text-indent") 30 | m = @hash["margin-left"].delete_suffix("em").to_i 31 | i = @hash["text-indent"].delete_suffix("em").to_i 32 | if i >= 0 33 | "m#{m}_i#{i}" 34 | else 35 | "m#{m}_j#{-i}" 36 | end 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/tasks/custom.rake: -------------------------------------------------------------------------------- 1 | namespace :custom do 2 | # 停用,完全按照 authority 的資料 3 | task :compare_creators => :environment do 4 | require_relative 'diff-creators' 5 | DiffCreators.diff 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/tasks/download.rake: -------------------------------------------------------------------------------- 1 | namespace :download do 2 | 3 | desc "下載電子書" 4 | task :ebooks, [:type] => :environment do |t, args| 5 | require "tasks/download_ebooks" 6 | c = DownloadEbooks.new.run(args[:type]) 7 | end 8 | end -------------------------------------------------------------------------------- /lib/tasks/export.rake: -------------------------------------------------------------------------------- 1 | namespace :export do 2 | desc "匯出存取紀錄" 3 | task :visits, [:d1,:d2] => :environment do |t, args| 4 | require "tasks/export_visits" 5 | exporter = ExportVisit.new 6 | exporter.export args[:d1], args[:d2] 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/tasks/export_visits.rb: -------------------------------------------------------------------------------- 1 | class ExportVisit 2 | def export(d1, d2) 3 | count = 0 4 | output_string = CSV.generate do |csv| 5 | csv << %w[url accessed_at count referer] 6 | rows = Visit.where("accessed_at BETWEEN ? AND ? ", d1, d2) 7 | count += rows.size 8 | rows.each do |v| 9 | csv << [v.url, v.accessed_at, v.count, v.referer] 10 | end 11 | end 12 | 13 | fn = Rails.root.join('data', 'visits.csv') 14 | puts "資料筆數: #{count}" 15 | puts "write #{fn}" 16 | File.write(fn, output_string) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/tasks/html-node.rb: -------------------------------------------------------------------------------- 1 | class HTMLNode 2 | attr_accessor :content, :attributes 3 | 4 | def initialize(tag) 5 | @tag = tag 6 | @attributes = {} 7 | @content = '' 8 | end 9 | 10 | def [] name 11 | @attributes[name] 12 | end 13 | 14 | def []= name, value 15 | set name.to_s, value.to_s 16 | end 17 | 18 | def copy_attributes(node) 19 | @attributes = node.attributes.dup 20 | end 21 | 22 | def end_tag 23 | "" 24 | end 25 | 26 | def open_tag 27 | r = "<#{@tag}" 28 | @attributes.each { |k,v| 29 | r += %( #{k}="#{v}") 30 | } 31 | r + ">" 32 | end 33 | 34 | def key?(k) 35 | @attributes.key?(k) 36 | end 37 | 38 | def set(name, value) 39 | @attributes[name] = value 40 | end 41 | 42 | def to_s 43 | open_tag + @content + end_tag 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/tasks/import_canons.rb: -------------------------------------------------------------------------------- 1 | class ImportCanons 2 | 3 | def initialize 4 | @canon_uuid = read_uuid 5 | end 6 | 7 | def import 8 | Canon.delete_all 9 | fn = File.join(Rails.application.config.cbeta_data, 'canons.yml') 10 | canons = YAML.load_file(fn) 11 | canons.each do |id, v| 12 | uuid = @canon_uuid[id] 13 | Canon.find_or_create_by(id2: id, uuid: uuid) do |c| 14 | c.name = v['short'] 15 | end 16 | end 17 | end 18 | 19 | private 20 | 21 | def read_uuid 22 | fn = Rails.root.join('data-static', 'uuid', 'canons.json') 23 | s = File.read(fn) 24 | JSON.parse(s) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/tasks/import_category.rb: -------------------------------------------------------------------------------- 1 | class ImportCategory 2 | def import 3 | Category.delete_all 4 | fn = Rails.root.join('data-static', 'categories.json') 5 | categories = JSON.load_file(fn) 6 | 7 | categories.each_pair do |k,v| 8 | Category.create(n: k.to_i, name: v) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/tasks/import_gaiji.rb: -------------------------------------------------------------------------------- 1 | class ImportGaiji 2 | def initialize 3 | @folder = Rails.application.config.cbeta_gaiji 4 | end 5 | 6 | def import 7 | $stderr.puts "destroy old gaijis" 8 | Gaiji.destroy_all 9 | fn = File.join(@folder, 'cbeta_gaiji.json') 10 | gaijis = JSON.parse(File.read(fn)) 11 | 12 | @inserts = [] 13 | gaijis.each do |k,v| 14 | if v.key? 'composition' 15 | pua = v['pua'].delete_prefix('U+').to_i(16) 16 | pua = [pua].pack 'U' 17 | @inserts << "('#{k}', '#{v['composition']}', '#{pua}')" 18 | end 19 | end 20 | 21 | $stderr.puts "執行 SQL insert 命令:#{number_to_human(@inserts.size)} records" 22 | sql = 'INSERT INTO gaijis ' 23 | sql << '("cb", "zzs", "pua")' 24 | sql << ' VALUES ' + @inserts.join(", ") 25 | $stderr.puts Benchmark.measure { 26 | ActiveRecord::Base.connection.execute(sql) 27 | } 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /lib/tasks/import_goto_abbrs.rb: -------------------------------------------------------------------------------- 1 | # 讀取 CBETA XML P5a,匯入卍續藏 行號對照表 2 | 3 | class ImportGotoAbbrs 4 | 5 | TABLE = 'goto_abbrs' 6 | 7 | def initialize 8 | @base = Rails.application.config.cbeta_data 9 | end 10 | 11 | def import() 12 | GotoAbbr.delete_all 13 | 14 | fn = File.join(@base, 'goto', 'goto-list.txt') 15 | @inserts = [] 16 | File.foreach(fn) do |line| 17 | line.chomp! 18 | if line.match /^(.*?)=(.*)$/ 19 | @inserts << "('#{$1}', '#{$2}')" 20 | end 21 | end 22 | 23 | sql = %[INSERT INTO #{TABLE} ("abbr", "ref")] 24 | sql << ' VALUES ' + @inserts.join(", ") 25 | ActiveRecord::Base.connection.execute(sql) 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /lib/tasks/import_jinglu_editors.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | 從 authority 經錄資料庫匯入作譯者資料 3 | =end 4 | require 'cbeta' 5 | require 'json' 6 | require 'pp' 7 | 8 | class ImportJingluEditors 9 | def initialize 10 | end 11 | 12 | def import 13 | fn = Rails.root.join('data', 'catalog', 'jl_editors.csv') 14 | end 15 | 16 | private 17 | 18 | end -------------------------------------------------------------------------------- /lib/tasks/import_visits.rb: -------------------------------------------------------------------------------- 1 | class ImportVisit 2 | def import 3 | fn = Rails.root.join('data', 'visits.csv') 4 | CSV.foreach(fn, headers: true) do |row| 5 | v = Visit.find_or_create_by( 6 | url: row['url'], 7 | referer: row['referer'], 8 | accessed_at: row['accessed_at'] 9 | ) 10 | v.update(count: v.count + row['count'].to_i) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/tasks/layers-ignore.txt: -------------------------------------------------------------------------------- 1 | 夔,虁,蘷,䕫 2 | 㝎,定 3 | 㬵,胶 4 | 亭,𠅘 5 | 堯,尭 6 | 壺,壼 7 | 寂,𡨜 8 | 寕,𡨴 9 | 嵊,𡹴 10 | 廷,𢌜 11 | 朂,勗 12 | 欝,欎 13 | 法,㳒 14 | 瀛,𤄞 15 | 睿,𧇖 16 | 笻,筇 17 | 簡,𥳑 18 | 蒙,䝉 19 | 郵,𨜚 20 | 點,㸃 21 | 𣲖,派 22 | 𦃺,緱 -------------------------------------------------------------------------------- /lib/tasks/quarterly.rake: -------------------------------------------------------------------------------- 1 | desc "每季執行" 2 | task :quarterly => :environment do |t, args| 3 | require_relative 'quarterly/quarterly' 4 | Quarterly.new.run 5 | end 6 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/change-log-font.rb: -------------------------------------------------------------------------------- 1 | class ChangeLogFont 2 | 3 | def initialize(config) 4 | @config = config 5 | @base = config[:change_log] 6 | end 7 | 8 | def run 9 | v = @config[:q2] 10 | handle_file("#{v}.htm") 11 | handle_file("#{v}-text.htm") 12 | handle_file("#{v}-punc.htm") 13 | end 14 | 15 | private 16 | 17 | def handle_file(f) 18 | fn = File.join(@base, f) 19 | html = File.read(fn) 20 | # Ext E, F 必須個別指定定型才能正確顯示 (2020-12-08 測試結果) 21 | # U+2B820..U+2CEA1, CJK Unified Ideographs Extension E, Unicode 8.0 22 | # U+2CEB0..U+2EBE0, CJK Unified Ideographs Extension F, Unicode 10.0 23 | html.gsub!(/[𫠠-𬺡𬺰-𮯠]/) do 24 | "#{$&}" 25 | end 26 | 27 | # 如果使用 ins, del 標記,在 ms word 開啟會出現「追蹤修訂」左邊線 28 | html.gsub!(//, '') 29 | html.gsub!(/<\/ins>/, '') 30 | html.gsub!(//, '') 31 | html.gsub!(/<\/del>/, '') 32 | File.write(fn, html) 33 | end 34 | 35 | end -------------------------------------------------------------------------------- /lib/tasks/quarterly/changelog.rb: -------------------------------------------------------------------------------- 1 | class Changelog 2 | def initialize(config) 3 | @config = config 4 | end 5 | 6 | def get_ignore_list 7 | { 8 | ignore_all: read_file('ignore-all'), 9 | ignore_puncs: read_file('ignore-puncs') 10 | } 11 | end 12 | 13 | private 14 | 15 | def read_file(type) 16 | fn = File.join(@config[:change_log], "#{@config[:q2]}-#{type}.txt") 17 | unless File.exist?(fn) 18 | puts "忽略清單不存在: #{fn}".red 19 | return [] 20 | end 21 | 22 | r = [] 23 | File.foreach(fn) do |line| 24 | r << line.split.first 25 | end 26 | r 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/check-new-canon.rb: -------------------------------------------------------------------------------- 1 | require 'csv' 2 | require 'set' 3 | require 'yaml' 4 | require_relative '../cbeta_p5a_share' 5 | 6 | include CbetaP5aShare 7 | 8 | puts '--' 9 | print "check new canon..." 10 | $base = ARGV.first 11 | 12 | path = File.join($base, 'cbeta-metadata', 'canons.yml') 13 | canons = YAML.load_file(path) 14 | 15 | path = File.join($base, 'cbeta-xml-p5a') 16 | new_canon = [] 17 | each_canon(path) do |c| 18 | next if canons.key?(c) 19 | new_canon << c 20 | end 21 | 22 | if new_canon.empty? 23 | puts "done." 24 | else 25 | puts "發現新藏經編號:" + new_canon.join(',') 26 | puts "必須更新 cbeta metadata, 請參考 doc/new-canon.md" 27 | abort 28 | end 29 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/epub-template/content.opf.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= @book_id %> <%= @title %> 5 | <%= @author %> 6 | <%= @epub_uid %> 7 | zh-TW 8 | <%= Date.today.to_s %> 9 | CBETA 10 | DILA 11 | https://www.cbeta.org/copyright.php 12 | 13 | 14 | 15 | 16 | 17 | 18 | <%= @manifest %> 19 | 20 | 21 | <%= @spin %> 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/epub-template/readme.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 說明 4 | 5 | 6 | 7 |
8 |

編輯說明

9 | 10 |
    11 |
  • 本電子書以「CBETA 電子佛典集成 Version %{version}」為資料來源。
  • 12 | 13 |
  • 漢字呈現以 Unicode 3.0 為基礎,不在此範圍的字則採用組字式表達。
  • 14 | 15 |
  • 梵文悉曇字及蘭札字均採用羅馬轉寫字,如無轉寫字則提供字型圖檔。
  • 16 | 17 |
  • CBETA 對底本所做的修訂用字以紅色字元表示。
  • 18 | 19 |
  • 若有發現任何問題,歡迎來函 service@cbeta.org 回報。
  • 20 | 21 |
  • 版權所有,歡迎自由流通,但禁止營利使用。
  • 22 |

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/epub-template/titlepage.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cover 6 | 10 | 11 | 12 |
13 | 17 | 18 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/epub-template/toc.ncx.erb: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%= @title %> 13 | 14 | <%= @nav_map %> 15 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/html-node.rb: -------------------------------------------------------------------------------- 1 | class HTMLNode 2 | attr_accessor :content 3 | def initialize(tag) 4 | @tag = tag 5 | @attributes = {} 6 | @content = '' 7 | end 8 | 9 | def [] name 10 | @attributes[name] 11 | end 12 | 13 | def []= name, value 14 | set name.to_s, value.to_s 15 | end 16 | 17 | def end_tag 18 | "" 19 | end 20 | 21 | def open_tag 22 | r = "<#{@tag}" 23 | @attributes.each { |k,v| 24 | r += %( #{k}="#{v}") 25 | } 26 | r + ">" 27 | end 28 | 29 | def set(name, value) 30 | @attributes[name] = value 31 | end 32 | 33 | def to_s 34 | open_tag + @content + end_tag 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/manticore-template-chunks.conf: -------------------------------------------------------------------------------- 1 | source chunks%{v} 2 | { 3 | type = xmlpipe2 4 | 5 | xmlpipe_command = cat /var/www/cbapi%{v}/shared/data/manticore-xml/chunks.xml 6 | 7 | xmlpipe_field_string = content 8 | 9 | xmlpipe_attr_multi = category_ids 10 | xmlpipe_attr_multi = creator_id 11 | 12 | xmlpipe_attr_string = category 13 | xmlpipe_attr_string = canon 14 | xmlpipe_attr_string = vol 15 | xmlpipe_attr_string = file 16 | xmlpipe_attr_string = work 17 | xmlpipe_attr_string = title 18 | xmlpipe_attr_string = dynasty 19 | xmlpipe_attr_string = creators 20 | xmlpipe_attr_string = creators_with_id 21 | xmlpipe_attr_string = lb 22 | xmlpipe_attr_string = linehead 23 | xmlpipe_attr_string = position_in_juan 24 | 25 | xmlpipe_attr_uint = juan 26 | xmlpipe_attr_uint = time_from 27 | xmlpipe_attr_uint = time_to 28 | } 29 | 30 | index chunks%{v} 31 | { 32 | source = chunks%{v} 33 | path = /var/lib/manticore/r%{v}-chunks/r%{v}-chunks 34 | 35 | charset_table = non_cjk 36 | ngram_len = 1 37 | ngram_chars = cjk, U+2F00..U+A4CF, U+F900..U+FAFF, U+FE30..U+FE4F, U+20000..U+2FA1F 38 | } 39 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/manticore-template-titles.conf: -------------------------------------------------------------------------------- 1 | source titles%{v} 2 | { 3 | type = xmlpipe2 4 | 5 | xmlpipe_command = cat /var/www/cbapi%{v}/shared/data/manticore-xml/titles.xml 6 | 7 | xmlpipe_field_string = content 8 | 9 | xmlpipe_attr_string = work 10 | xmlpipe_attr_string = canon 11 | xmlpipe_attr_string = canon_order 12 | } 13 | 14 | index titles%{v} 15 | { 16 | source = titles%{v} 17 | path = /var/lib/manticore/r%{v}-titles/r%{v}-titles 18 | 19 | charset_table = non_cjk 20 | ngram_len = 1 21 | ngram_chars = cjk, U+2F00..U+A4CF, U+F900..U+FAFF, U+FE30..U+FE4F, U+20000..U+2FA1F 22 | } 23 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/mobi.rb: -------------------------------------------------------------------------------- 1 | # 使用 Calibre 附的 command line 工具 ebook-convert 2 | # https://manual.calibre-ebook.com/generated/en/ebook-convert.html 3 | 4 | require 'colorize' 5 | require 'fileutils' 6 | 7 | class Epub2Mobi 8 | def initialize(config) 9 | @converter = config[:ebook_convert] 10 | @epub_base = config[:epub] 11 | @mobi_base = config[:mobi] 12 | end 13 | 14 | def convert 15 | Dir.entries(@epub_base).sort.each do |c| 16 | next if c.start_with?('.') 17 | p1 = File.join(@epub_base, c) 18 | p2 = File.join(@mobi_base, c) 19 | convert_canon(p1, p2) 20 | end 21 | end 22 | 23 | private 24 | 25 | def convert_canon(src, dest) 26 | FileUtils.makedirs(dest) 27 | 28 | Dir.entries(src).sort.each do |f| 29 | next if f.start_with?('.') 30 | p1 = File.join(src, f) 31 | p2 = File.join(dest, f.sub(/\.epub$/, '.mobi')) 32 | cmd = "#{@converter} #{p1} #{p2}" 33 | puts '-' * 10 34 | puts File.basename(f, '.*').green 35 | puts cmd 36 | abort unless system(cmd) 37 | end 38 | end 39 | 40 | end -------------------------------------------------------------------------------- /lib/tasks/quarterly/runbook-ebook.rb: -------------------------------------------------------------------------------- 1 | require 'runbook' 2 | 3 | module RunbookSectionEbook 4 | def define_section_ebook(config) 5 | Runbook.section "製作電子書" do 6 | step '製作 EPUB' do 7 | ruby_command do |rb_cmd, metadata, run| 8 | require_relative 'epub-main' 9 | CbetaEbook.new(config).convert 10 | end 11 | end 12 | 13 | step '壓縮全部 EPUB' do 14 | ruby_command do |rb_cmd, metadata, run| 15 | q = config[:q2].downcase 16 | dest = "cbeta-epub-#{q}.zip" 17 | 18 | # 變更目前目錄再做壓縮,否則壓縮檔內會含路徑 19 | Dir.chdir(config[:download]) do 20 | FileUtils.remove_file(dest, force: true) 21 | system "zip -r #{dest} epub" 22 | end 23 | 24 | puts "交由 heaven 將 EPUB 轉為 MOBI, PDF:" 25 | puts "https://cbdata.dila.edu.tw/dev/download/cbeta-epub-#{q}.zip" 26 | end 27 | end 28 | 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/runbook-prepare-cn.rb: -------------------------------------------------------------------------------- 1 | #require 'net/sftp' 2 | require 'runbook' 3 | 4 | module PrepareCN 5 | def define_section_prepare(config) 6 | Runbook.section "前置作業 (runbook-prepare.rb)" do 7 | step 'update_from_github (update-github.rb)' do 8 | command "ruby update-github.rb #{config[:git]} #{config[:q2]}" 9 | end 10 | 11 | step '產生 Juanline 資料 (juanline.rb)' do 12 | ruby_command do |rb_cmd, metadata, run| 13 | require_relative 'juanline' 14 | Juanline.new.produce 15 | end 16 | end 17 | 18 | step '匯入缺字資料' do 19 | command 'rake db:migrate' 20 | command 'rake import:gaiji' 21 | end 22 | 23 | step 'convert xml to html (rake convert:x2h)' do 24 | command "rake convert:x2h[#{config[:publish]}]" 25 | end 26 | 27 | end 28 | end 29 | end -------------------------------------------------------------------------------- /lib/tasks/quarterly/section-check.rb: -------------------------------------------------------------------------------- 1 | module SectionCheck 2 | def run_section_check 3 | run_section "檢查作業 (section-check.rb)" do 4 | cmd = 'rake check:authority' 5 | run_step "check authority (#{cmd})" do 6 | command cmd 7 | end 8 | 9 | cmd = 'rake check:p5a' 10 | run_step "check cbeta xml (#{cmd})" do 11 | command cmd 12 | end 13 | 14 | run_step '檢查缺字資料' do 15 | command 'rake check:gaiji' 16 | end 17 | 18 | run_step '匯入缺字資料' do 19 | # 這似乎會將 cb_analytics 也清空 20 | #unless Rails.env.development? 21 | # command 'rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1' 22 | #end 23 | command 'rake db:migrate' 24 | command 'rake import:gaiji' 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/section-download-ebooks.rb: -------------------------------------------------------------------------------- 1 | module SectionDownloadEbooks 2 | def run_section_download_ebooks 3 | run_section "從 CBETA 下載 Heaven 製作的 EPUB, Mobi, PDF 電子書" do 4 | run_step '下載 EPUB, Mobi, PDF' do 5 | command 'rake download:ebooks' 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/section-html.rb: -------------------------------------------------------------------------------- 1 | module SectionHTML 2 | def run_section_html 3 | run_section "產生 HTML 供 Heaven 比對 (section-html.rb)" do 4 | run_step 'convert xml to html (rake convert:x2h)' do 5 | require_relative '../convert_x2h' 6 | c = ConvertX2h.new 7 | c.convert(@config[:publish]) 8 | end 9 | 10 | run_step '匯入佛寺志等 Layers' do 11 | command "rake import:layers" 12 | end 13 | 14 | run_step '打包 html 給 heaven' do 15 | step_zip_html 16 | end 17 | end 18 | end 19 | 20 | def step_zip_html 21 | # 變更目前目錄再做壓縮,否則壓縮檔內會含路徑 22 | Dir.chdir(@config[:data]) do 23 | # 先刪除舊檔, 否則 zip 裡的舊檔會保留 24 | FileUtils.remove_file('html.zip', force: true) 25 | command "zip -r html.zip html" 26 | end 27 | 28 | src = File.join(@config[:data], 'html.zip') 29 | confirm <<~MSG 30 | 將 zip 檔提供給 heaven: 31 | #{src} 32 | => 33 | GoogleDrive/共用雲端硬碟/CBETA-季更新/html.zip 34 | 因為 heaven 可能發現問題再修改 XML, 35 | 所以等 heaven 比對完再進行後面的步驟。 36 | MSG 37 | end 38 | end # end of module 39 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/section-kwic.rb: -------------------------------------------------------------------------------- 1 | module SectionKwic 2 | def run_section_kwic 3 | run_section "KWIC" do 4 | run_step 'suffix array (約11小時)' do 5 | command "rake kwic:x2h" 6 | command "rake kwic:h2t" # simple html => txt, 全部做一次大約花 7 小時 7 | command "rake kwic:sa" # suffix array, 約4小時 8 | 9 | # 只有單卷 index, 不必 sort 了 10 | # puts '重排 info.dat, 為了加速讀取 info.dat, 根據 sa 的順序重排 info.dat' 11 | # puts '約 1小時46分' 12 | # command "rake kwic:sort_info" 13 | end 14 | 15 | run_step '將 suffix array 移至正式資料夾使用' do 16 | command "rake kwic:rotate" 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/sphinx-template-chunks.conf: -------------------------------------------------------------------------------- 1 | source chunks%{v} 2 | { 3 | type = xmlpipe2 4 | 5 | xmlpipe_command = cat /var/www/cbapi%{v}/shared/data/sphinx-xml/chunks.xml 6 | 7 | xmlpipe_field_string = content 8 | 9 | xmlpipe_attr_multi = category_ids 10 | xmlpipe_attr_multi = creator_id 11 | 12 | xmlpipe_attr_string = category 13 | xmlpipe_attr_string = canon 14 | xmlpipe_attr_string = vol 15 | xmlpipe_attr_string = file 16 | xmlpipe_attr_string = work 17 | xmlpipe_attr_string = title 18 | xmlpipe_attr_string = dynasty 19 | xmlpipe_attr_string = creators 20 | xmlpipe_attr_string = creators_with_id 21 | xmlpipe_attr_string = lb 22 | xmlpipe_attr_string = linehead 23 | 24 | xmlpipe_attr_uint = juan 25 | xmlpipe_attr_uint = time_from 26 | xmlpipe_attr_uint = time_to 27 | } 28 | 29 | index chunks%{v} 30 | { 31 | source = chunks%{v} 32 | path = /var/lib/sphinx/data%{v}-chunks/cbeta 33 | #charset_table = 0..9, english, U+3000..U+2FA1F 34 | ngram_len = 1 35 | ngram_chars = U+3000..U+2FA1F 36 | } 37 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/sphinx-template-notes.conf: -------------------------------------------------------------------------------- 1 | source notes%{v} 2 | { 3 | type = xmlpipe2 4 | 5 | xmlpipe_command = cat /var/www/cbapi%{v}/shared/data/sphinx-xml/notes.xml 6 | 7 | #xmlpipe_field = content 8 | xmlpipe_field_string = content 9 | 10 | # xmlpipe2 attribute declaration 11 | xmlpipe_attr_multi = category_ids 12 | xmlpipe_attr_multi = creator_id 13 | 14 | xmlpipe_attr_string = category 15 | xmlpipe_attr_string = canon 16 | xmlpipe_attr_string = vol 17 | xmlpipe_attr_string = file 18 | xmlpipe_attr_string = work 19 | xmlpipe_attr_string = title 20 | xmlpipe_attr_string = dynasty 21 | xmlpipe_attr_uint = time_from 22 | xmlpipe_attr_uint = time_to 23 | xmlpipe_attr_string = creators 24 | xmlpipe_attr_string = creators_with_id 25 | xmlpipe_attr_string = lb 26 | xmlpipe_attr_string = n 27 | xmlpipe_attr_string = canon_order 28 | xmlpipe_attr_uint = juan 29 | xmlpipe_attr_string = prefix 30 | xmlpipe_attr_string = suffix 31 | } 32 | 33 | index notes%{v} 34 | { 35 | source = notes%{v} 36 | path = /var/lib/sphinx/data%{v}-notes/cbeta 37 | #charset_table = 0..9, english, U+3000..U+2FA1F 38 | ngram_len = 1 39 | ngram_chars = U+3000..U+2FA1F 40 | } 41 | -------------------------------------------------------------------------------- /lib/tasks/quarterly/sphinx-template-titles.conf: -------------------------------------------------------------------------------- 1 | source titles%{v} 2 | { 3 | type = xmlpipe2 4 | 5 | xmlpipe_command = cat /var/www/cbapi%{v}/shared/data/sphinx-xml/titles.xml 6 | 7 | xmlpipe_field_string = title 8 | 9 | xmlpipe_attr_string = work 10 | xmlpipe_attr_string = canon 11 | xmlpipe_attr_string = canon_order 12 | } 13 | 14 | index titles%{v} 15 | { 16 | source = titles%{v} 17 | path = /var/lib/sphinx/data%{v}-titles/cbeta 18 | #charset_table = 0..9, english, U+3000..U+2FA1F 19 | ngram_len = 1 20 | ngram_chars = U+3000..U+2FA1F 21 | } 22 | -------------------------------------------------------------------------------- /lib/tasks/update.rake: -------------------------------------------------------------------------------- 1 | require 'pp' 2 | include ActionView::Helpers::NumberHelper 3 | 4 | namespace :update do 5 | 6 | desc "更新經號排序" 7 | task :sort_order => :environment do 8 | @work_sort_order = {} 9 | Work.find_each.with_index do |w, i| 10 | if (i % 1000) == 0 11 | print "\rupdate work.sort_order #{number_with_delimiter(i)}" 12 | end 13 | w.sort_order = sort_order(w.n) + w.n 14 | w.save 15 | end 16 | puts 17 | 18 | TocNode.find_each.with_index do |row, i| 19 | if (i % 1000) == 0 20 | print "\rupdate toc_node.sort_order #{number_with_delimiter(i)}" 21 | end 22 | row.sort_order = sort_order(row.work) + row.work 23 | row.save 24 | end 25 | puts 26 | end 27 | 28 | # @param n [String] 佛典編號 29 | # @return [String] 排序用編號 30 | def sort_order(n) 31 | return @work_sort_order[n] if @work_sort_order.key? n 32 | 33 | canon = CBETA.get_canon_id_from_work_id(n) 34 | r = CBETA.get_sort_order_from_canon_id(canon) 35 | 36 | @work_sort_order[n] = r 37 | r 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/log/.keep -------------------------------------------------------------------------------- /public/api-docs/api/collections.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Get the list of all collections 3 | tags: [rise_shine] 4 | responses: 5 | '200': 6 | description: List of Collections 7 | content: 8 | application/json: 9 | schema: 10 | type: array 11 | items: 12 | type: object 13 | properties: 14 | uuid: 15 | type: string 16 | format: uuid 17 | name: 18 | type: string 19 | example: A 金藏 20 | resourceCount: 21 | type: integer 22 | -------------------------------------------------------------------------------- /public/api-docs/api/collections_x_resources.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Get the list of all resources for a collection 3 | tags: [rise_shine] 4 | parameters: 5 | - name: uuid 6 | in: path 7 | required: true 8 | description: The UUID of the Collection you wish to access 9 | schema: 10 | type: string 11 | format: uuid 12 | responses: 13 | '200': 14 | description: list of resources (works) 15 | content: 16 | application/json: 17 | schema: 18 | type: array 19 | items: 20 | type: object 21 | properties: 22 | uuid: 23 | type: string 24 | format: uuid 25 | name: 26 | type: string 27 | example: "T0001 長阿含經" 28 | -------------------------------------------------------------------------------- /public/api-docs/api/resources_x_sections.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Get the list of all sections (卷) for a resource (work) 3 | tags: [rise_shine] 4 | parameters: 5 | - name: uuid 6 | in: path 7 | required: true 8 | description: The UUID of the Resource you wish to access 9 | schema: 10 | type: string 11 | format: uuid 12 | responses: 13 | '200': 14 | description: list of sections (卷) 15 | content: 16 | application/json: 17 | schema: 18 | type: array 19 | items: 20 | type: object 21 | properties: 22 | uuid: 23 | type: string 24 | format: uuid 25 | name: 26 | type: string 27 | example: T0001 長阿含經 第1卷 28 | -------------------------------------------------------------------------------- /public/api-docs/api/sections_x.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Get one section's (卷) information 3 | tags: [rise_shine] 4 | parameters: 5 | - name: uuid 6 | in: path 7 | required: true 8 | description: The UUID of the Section you wish to access 9 | schema: 10 | type: string 11 | format: uuid 12 | responses: 13 | '200': 14 | description: list of sections (卷) 15 | content: 16 | application/json: 17 | schema: 18 | type: object 19 | properties: 20 | uuid: 21 | type: string 22 | format: uuid 23 | title: 24 | type: string 25 | example: T0001 長阿含經 第1卷 26 | parentUuid: 27 | type: string 28 | format: uuid 29 | uri: 30 | type: string 31 | description: the original uri from which the section can be fetched 32 | example: "http://cbdata.dila.edu.tw/v1.2/download/text-for-asia-network/T/T0001/T0001_001.txt" 33 | contentUnitCount: 34 | type: integer 35 | example: 1 36 | -------------------------------------------------------------------------------- /public/api-docs/api/sections_x_content_units.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Get the list of all content units for a section (卷) 3 | tags: [rise_shine] 4 | parameters: 5 | - name: uuid 6 | in: path 7 | required: true 8 | description: The UUID of the Section you wish to access 9 | schema: 10 | type: string 11 | format: uuid 12 | responses: 13 | '200': 14 | description: list of sections (卷) 15 | content: 16 | application/json: 17 | schema: 18 | type: array 19 | items: 20 | type: object 21 | properties: 22 | uuid: 23 | type: string 24 | format: uuid 25 | title: 26 | type: string 27 | example: T0001 長阿含經 第1卷 28 | contents: 29 | type: string 30 | description: 該卷文字內容 31 | -------------------------------------------------------------------------------- /public/api-docs/catalog_entry/_.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Returns a catalog entry information, including its children. 3 | tags: [catalog] 4 | parameters: 5 | - $ref: 'parameters.yaml' 6 | responses: 7 | '200': 8 | description: A Catalog Entry Object 9 | content: 10 | application/json: 11 | schema: 12 | $ref: response.yaml 13 | # examples: 14 | # $ref: 'response-examples.yaml' 15 | -------------------------------------------------------------------------------- /public/api-docs/catalog_entry/parameters.yaml: -------------------------------------------------------------------------------- 1 | name: q 2 | in: query 3 | required: false 4 | schema: 5 | type: string 6 | description: Catalog Entry ID 7 | examples: 8 | root: 9 | value: root 10 | summary: get various CBETA catalogs (根目錄, 取得 CBETA 各種目錄) 11 | category: 12 | value: CBETA 13 | summary: CBETA Catalog by Categories (CBETA 部類目錄) 14 | orig: 15 | value: orig 16 | summary: Catalog in Source Collection (原書目錄) 17 | taisho: 18 | value: orig-T 19 | summary: 《大正藏》原書目錄。其他各藏,依此類推在 "orig-" 之後加上藏經 ID。 20 | -------------------------------------------------------------------------------- /public/api-docs/catalog_entry/response-examples.yaml: -------------------------------------------------------------------------------- 1 | node_type_alt: 2 | summary: 如果 node_type 為 'alt' 表示 CBETA 未收錄此經全文,而是對應到其他藏經的全文。 3 | value: 4 | num_found: 42 5 | label: J01 6 | results: 7 | - n: "orig-J.001.001" 8 | label: "JA001(=T0293) 大方廣佛華嚴經 (40卷)" 9 | node_type: alt 10 | juan_range: 11 | summary: 目錄節點所指向的可能是某部佛典的部份卷數,例如: q=CBETA.003.001 12 | value: 13 | num_found: 2 14 | label: 01 上品般若(大般若經第1會) T05-06 15 | results: 16 | - n: CBETA.003.001.001 17 | work: T0220 18 | label: T0220 大般若波羅蜜多經(第1卷-第200卷) 19 | category: 般若部類 20 | creators: 玄奘 21 | juan_start: 1 22 | juan_end: 200 23 | file: T05n0220a 24 | node_type: work 25 | -------------------------------------------------------------------------------- /public/api-docs/catalog_entry/response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of child entries 6 | # label: 7 | # type: string 8 | # description: catalog entry label 9 | # results: 10 | # type: array 11 | # description: list of child entries 12 | # items: 13 | # type: object 14 | # properties: 15 | # n: 16 | # type: string 17 | # description: child entry id. 可用於取得下層目錄。例如: catalog_entry?q=CBETA.001 18 | # label: 19 | # type: string 20 | # description: child entry label 21 | # node_type: 22 | # type: string 23 | # description: 如果 node_type 為 'alt' 表示 CBETA 未收錄此經全文,而是對應到其他藏經的全文。 24 | # juan_start: 25 | # type: integer 26 | # description: 目錄節點所指向的可能是某部佛典的部份卷數,例如:`catalog_entry?q=CBETA.003.001` 27 | # juan_end: 28 | # type: integer 29 | # file: 30 | # type: string 31 | -------------------------------------------------------------------------------- /public/api-docs/chinese_tools/sc2tc.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 中文簡體轉繁體 3 | tags: [tool] 4 | parameters: 5 | - name: q 6 | in: query 7 | required: true 8 | schema: 9 | type: string 10 | example: 简体转繁体 11 | responses: 12 | '200': 13 | description: 轉換後的繁體中文 14 | content: 15 | text/plain: 16 | schema: 17 | type: string 18 | example: 簡體轉繁體 19 | -------------------------------------------------------------------------------- /public/api-docs/common/resources.yaml: -------------------------------------------------------------------------------- 1 | schema: 2 | canon_id: 3 | type: string 4 | enum: [A, B, C, CC, D, F, G, GA, GB, I, J, K, L, LC, M, N, P, S, T, TX, U, X, Y, ZS, ZW] 5 | -------------------------------------------------------------------------------- /public/api-docs/download/docusky.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 Docusky XML 格式佛典 3 | tags: [download] 4 | parameters: 5 | - name: filename 6 | in: path 7 | description: 佛典編號(經號) 或 佛典編號(經號)+ 卷號(三碼) 8 | required: true 9 | schema: 10 | type: string 11 | examples: 12 | juan: 13 | summary: 單卷 14 | value: A0157_001 15 | work: 16 | summary: 整部佛典 17 | value: A0157 18 | responses: 19 | '200': 20 | description: XML File 21 | content: 22 | text/xml: 23 | schema: 24 | type: string 25 | -------------------------------------------------------------------------------- /public/api-docs/download/epub-all.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 CBETA 某季全部 EPUB 3 | tags: [download] 4 | description: 只提供最新一季 5 | responses: 6 | '200': 7 | description: ZIP File 8 | content: 9 | application/zip: 10 | schema: 11 | type: string 12 | format: binary 13 | -------------------------------------------------------------------------------- /public/api-docs/download/epub.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 EPUB 3 | tags: [download] 4 | parameters: 5 | - name: canon 6 | in: path 7 | description: 藏經 ID 8 | required: true 9 | schema: 10 | type: string 11 | example: A 12 | - name: work 13 | in: path 14 | description: 佛典編號(經號) 15 | required: true 16 | schema: 17 | type: string 18 | example: A0157 19 | responses: 20 | '200': 21 | description: EPUB File 22 | content: 23 | application/epub+zip: 24 | schema: 25 | type: string 26 | format: binary 27 | -------------------------------------------------------------------------------- /public/api-docs/download/footnotes.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載某一卷文本中的校注 3 | tags: [download] 4 | parameters: 5 | - name: canon 6 | in: path 7 | description: 藏經 ID 8 | required: true 9 | schema: 10 | type: string 11 | example: T 12 | - name: work 13 | in: path 14 | description: 佛典編號(經號) 15 | required: true 16 | schema: 17 | type: string 18 | example: T0001 19 | - name: juan 20 | in: path 21 | description: 卷號(三碼) 22 | required: true 23 | schema: 24 | type: string 25 | example: 001 26 | responses: 27 | '200': 28 | description: csv file of footnotes 29 | content: 30 | text/csv: 31 | schema: 32 | type: string 33 | -------------------------------------------------------------------------------- /public/api-docs/download/html_work.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 HTML 格式佛典,壓縮為 ZIP 檔。 3 | tags: [download] 4 | description: 解壓縮之後有多個 HTML 檔,適合直接閱讀用。 5 | parameters: 6 | - name: work 7 | in: path 8 | description: 佛典編號(經號) 9 | required: true 10 | schema: 11 | type: string 12 | example: A0157 13 | responses: 14 | '200': 15 | description: ZIP File 16 | content: 17 | application/zip: 18 | schema: 19 | type: string 20 | format: binary 21 | -------------------------------------------------------------------------------- /public/api-docs/download/html_work_juan.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載某一卷 HTML (適合直接閱讀用) 3 | tags: [download] 4 | parameters: 5 | - name: work_juan 6 | in: path 7 | description: 佛典編號(經號) + 卷號(三碼) 8 | required: true 9 | schema: 10 | type: string 11 | example: A1057_001 12 | responses: 13 | '200': 14 | description: HTML File 15 | content: 16 | text/html: 17 | schema: 18 | type: string 19 | -------------------------------------------------------------------------------- /public/api-docs/download/mobi-all.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 CBETA 某季全部 MOBI 3 | tags: [download] 4 | description: 只提供最新一季 5 | responses: 6 | '200': 7 | description: ZIP File 8 | content: 9 | application/zip: 10 | schema: 11 | type: string 12 | format: binary 13 | -------------------------------------------------------------------------------- /public/api-docs/download/mobi.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 MOBI 格式 3 | tags: [download] 4 | parameters: 5 | - name: canon 6 | in: path 7 | description: 藏經 ID 8 | required: true 9 | schema: 10 | type: string 11 | example: A 12 | - name: work 13 | in: path 14 | description: 佛典編號(經號) 15 | required: true 16 | schema: 17 | type: string 18 | example: A0157 19 | responses: 20 | '200': 21 | description: MOBI File 22 | content: 23 | application/x-mobipocket-ebook: 24 | schema: 25 | type: string 26 | format: binary 27 | -------------------------------------------------------------------------------- /public/api-docs/download/pdf.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 PDF 3 | tags: [download] 4 | parameters: 5 | - name: canon 6 | in: path 7 | description: 藏經 ID 8 | required: true 9 | schema: 10 | type: string 11 | example: A 12 | - name: work 13 | in: path 14 | description: 佛典編號(經號) 15 | required: true 16 | schema: 17 | type: string 18 | example: A0157 19 | responses: 20 | '200': 21 | description: PDF File 22 | content: 23 | application/pdf: 24 | schema: 25 | type: string 26 | format: binary 27 | -------------------------------------------------------------------------------- /public/api-docs/download/text.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 下載 某部或某卷 純文字版 ZIP 檔 3 | tags: [download] 4 | description: | 5 | ## 悉曇字 6 | 7 | 以羅馬轉寫呈現,例: /download/text/T0864A.txt.zip 8 | 9 | ## 圖形 10 | 11 | 以【圖:T16p0845_01.gif】表示,圖檔也一起包含在 zip 檔裡。 12 | 13 | 例: /download/text/T0719_001.txt.zip 14 | 15 | ## 表格 16 | 17 | 逐列、逐欄 分行呈現,例: /download/text/T2035_003.txt.zip 18 | 19 | ○四處十六會圖 20 | parameters: 21 | - name: work_juan 22 | in: path 23 | description: 佛典編號(經號) 或 佛典編號(經號)+ 卷號(三碼) 24 | required: true 25 | schema: 26 | type: string 27 | examples: 28 | work: 29 | value: T0001 30 | summary: 指定 佛典編號,取得某部佛典 31 | work_juan: 32 | value: T0001_001 33 | summary: 指定 佛典編號+卷號 取得某一卷 34 | responses: 35 | '200': 36 | description: ZIP File 37 | content: 38 | application/zip: 39 | schema: 40 | type: string 41 | format: binary 42 | -------------------------------------------------------------------------------- /public/api-docs/export-all_creators-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of creators 6 | results: 7 | type: array 8 | description: list of creators 9 | items: 10 | type: array 11 | description: 第一個元素是作譯者 ID,第二個元素是作譯者名稱。 12 | items: 13 | type: string 14 | example: ["A000001", "金總持"] -------------------------------------------------------------------------------- /public/api-docs/export/all-creators.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 全部作譯者列表 3 | tags: [export] 4 | responses: 5 | '200': 6 | description: list of creators 7 | content: 8 | application/json: 9 | schema: 10 | type: object 11 | properties: 12 | num_found: 13 | type: integer 14 | description: number of creators 15 | results: 16 | type: array 17 | description: list of creators 18 | items: 19 | type: array 20 | description: 第一個元素是作譯者 ID,第二個元素是作譯者名稱。 21 | items: 22 | type: string 23 | example: ["A000001", "金總持"] 24 | -------------------------------------------------------------------------------- /public/api-docs/export/all_creators2.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 全部作譯者列表 (含別名) 3 | tags: [export] 4 | responses: 5 | '200': 6 | description: list of creators (including alias) 7 | content: 8 | application/json: 9 | schema: 10 | type: object 11 | properties: 12 | num_found: 13 | type: integer 14 | description: number of creators 15 | results: 16 | type: object 17 | description: hash of creators, key 是作譯者 id 18 | example: 19 | A000001: 20 | regular_name: 金總持 21 | aliases_all: ["金揔持","寶輪大師","明因妙善普濟法師"] 22 | -------------------------------------------------------------------------------- /public/api-docs/export/all_works.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 全部典籍列表 3 | tags: [export] 4 | responses: 5 | '200': 6 | description: list of all works 7 | content: 8 | application/json: 9 | schema: 10 | type: array 11 | items: 12 | type: object 13 | properties: 14 | work: 15 | type: string 16 | description: 佛典編號 17 | example: T0001 18 | title: 19 | type: string 20 | description: 佛典標題(經名) 21 | example: 長阿含經 22 | juans: 23 | type: array 24 | description: 卷號列表 25 | items: 26 | type: string 27 | example: ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22"] 28 | -------------------------------------------------------------------------------- /public/api-docs/export/check_list.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 嘉興藏檢查表 3 | tags: [export] 4 | parameters: 5 | - name: canon 6 | in: query 7 | description: 藏經 ID 8 | required: true 9 | schema: 10 | type: string 11 | example: J 12 | responses: 13 | '200': 14 | description: 嘉興藏 佛典、卷 列表 15 | content: 16 | text/csv: 17 | schema: 18 | type: string 19 | -------------------------------------------------------------------------------- /public/api-docs/export/creator_strokes.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 範圍選擇清單-依作譯者筆劃 3 | tags: [export] 4 | description: 供前端做「範圍選擇」樹狀目錄使用。 5 | responses: 6 | '200': 7 | description: Tree 8 | content: 9 | application/json: 10 | schema: 11 | type: object 12 | properties: 13 | title: 14 | type: string 15 | description: Title of Tree Root Node 16 | example: '選擇全部' 17 | children: 18 | type: array 19 | items: 20 | type: object 21 | description: Tree Node 22 | -------------------------------------------------------------------------------- /public/api-docs/export/creator_strokes_works.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 範圍選擇清單-依作譯者筆劃 (含譯著) 3 | tags: [export] 4 | description: 供前端做「範圍選擇」樹狀目錄使用。 5 | responses: 6 | '200': 7 | description: Tree 8 | content: 9 | application/json: 10 | schema: 11 | type: object 12 | properties: 13 | title: 14 | type: string 15 | description: Title of Tree Root Node 16 | example: '選擇全部' 17 | children: 18 | type: array 19 | items: 20 | type: object 21 | description: Tree Node 22 | -------------------------------------------------------------------------------- /public/api-docs/export/dynasty.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 朝代列表 3 | tags: [export] 4 | responses: 5 | '200': 6 | description: 全部朝代列表,及其起始年、結束年、佛典數。 7 | content: 8 | application/json: 9 | schema: 10 | type: object 11 | properties: 12 | num_found: 13 | type: integer 14 | description: number of dynasties 15 | results: 16 | type: string 17 | description: CSV 18 | example: "朝代,起始年,結束年,佛典數\n東漢,25,220,80" 19 | -------------------------------------------------------------------------------- /public/api-docs/export/dynasty_works.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 範圍選擇清單-依朝代期間佛典列表 3 | tags: [export] 4 | description: 供前端做「範圍選擇」樹狀目錄使用。 5 | responses: 6 | '200': 7 | description: Tree 8 | content: 9 | application/json: 10 | schema: 11 | type: object 12 | properties: 13 | title: 14 | type: string 15 | description: Title of Tree Root Node 16 | example: '選擇全部' 17 | children: 18 | type: array 19 | items: 20 | type: object 21 | description: Tree Node 22 | -------------------------------------------------------------------------------- /public/api-docs/export/scope_selector_by_category.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 範圍選擇清單-依部類 3 | tags: [export] 4 | description: 供前端做「範圍選擇」樹狀目錄使用。 5 | responses: 6 | '200': 7 | description: Tree 8 | content: 9 | application/json: 10 | schema: 11 | type: object 12 | properties: 13 | title: 14 | type: string 15 | description: Title of Tree Root Node 16 | example: '選擇全部' 17 | key: 18 | type: string 19 | description: Key of Tree Node 20 | children: 21 | type: array 22 | items: 23 | type: object 24 | description: Tree Node 25 | -------------------------------------------------------------------------------- /public/api-docs/export/scope_selector_by_vol.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 範圍選擇清單-依刊本 3 | tags: [export] 4 | description: 供前端做「範圍選擇」樹狀目錄使用。 5 | responses: 6 | '200': 7 | description: Tree 8 | content: 9 | application/json: 10 | schema: 11 | type: object 12 | properties: 13 | title: 14 | type: string 15 | description: Title of Tree Root Node 16 | example: '選擇全部' 17 | key: 18 | type: string 19 | description: Key of Tree Node 20 | children: 21 | type: array 22 | items: 23 | type: object 24 | description: Tree Node 25 | -------------------------------------------------------------------------------- /public/api-docs/juans/_.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 佛典的某一卷 3 | tags: [juan] 4 | parameters: 5 | - $ref: parameters.yaml#/work 6 | - $ref: parameters.yaml#/juan 7 | - $ref: parameters.yaml#/work_info 8 | - $ref: parameters.yaml#/toc 9 | responses: 10 | '200': 11 | description: 某一卷的文本內容 in HTML format. 12 | content: 13 | application/json: 14 | schema: 15 | $ref: response.yaml 16 | -------------------------------------------------------------------------------- /public/api-docs/juans/goto-parameters.yaml: -------------------------------------------------------------------------------- 1 | canon: 2 | in: query 3 | name: canon 4 | required: false 5 | description: 藏經 ID 6 | example: T 7 | schema: 8 | type: string 9 | work: 10 | in: query 11 | name: work 12 | required: false 13 | description: 佛典編號 14 | example: 1 15 | schema: 16 | type: string 17 | juan: 18 | in: query 19 | name: juan 20 | required: false 21 | description: 卷號 22 | example: 1 23 | schema: 24 | type: integer 25 | vol: 26 | in: query 27 | name: vol 28 | required: false 29 | description: 冊號 30 | example: 1 31 | schema: 32 | type: integer 33 | page: 34 | in: query 35 | name: page 36 | required: false 37 | description: 頁碼 38 | example: 1 39 | schema: 40 | type: integer 41 | col: 42 | in: query 43 | name: col 44 | required: false 45 | description: 欄號 46 | example: a 47 | schema: 48 | type: string 49 | line: 50 | in: query 51 | name: line 52 | required: false 53 | description: 行號 54 | example: 1 55 | schema: 56 | type: integer 57 | linehead: 58 | in: query 59 | name: linehead 60 | required: false 61 | description: 行首資訊 62 | example: T01n0001_p0066c25 63 | schema: 64 | type: string 65 | -------------------------------------------------------------------------------- /public/api-docs/juans/goto-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found 6 | example: 1 7 | results: 8 | type: array 9 | description: list of result 10 | items: 11 | type: object 12 | properties: 13 | vol: 14 | type: string 15 | description: 冊號 16 | example: T01 17 | work: 18 | type: string 19 | description: 佛典編號 20 | example: T0001 21 | file: 22 | type: string 23 | description: XML 檔主檔名 24 | example: T01n0001 25 | juan: 26 | type: integer 27 | description: 卷號 28 | example: 1 29 | lb: 30 | type: string 31 | description: 行號 32 | example: 0001a01 33 | title: 34 | type: string 35 | description: Work's Titie (經名) 36 | example: 長阿含經 -------------------------------------------------------------------------------- /public/api-docs/juans/goto.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Goto 3 | tags: [juan] 4 | externalDocs: 5 | url: 'https://github.com/DILA-edu/cbeta-api/blob/main/openapi/juans/goto.md' 6 | parameters: 7 | - $ref: goto-parameters.yaml#/canon 8 | - $ref: goto-parameters.yaml#/work 9 | - $ref: goto-parameters.yaml#/juan 10 | - $ref: goto-parameters.yaml#/vol 11 | - $ref: goto-parameters.yaml#/page 12 | - $ref: goto-parameters.yaml#/col 13 | - $ref: goto-parameters.yaml#/line 14 | - $ref: goto-parameters.yaml#/linehead 15 | responses: 16 | '200': 17 | description: 回傳 Goto 所需相關資訊. 18 | content: 19 | application/json: 20 | schema: 21 | $ref: goto-response.yaml 22 | -------------------------------------------------------------------------------- /public/api-docs/juans/parameters.yaml: -------------------------------------------------------------------------------- 1 | work: 2 | in: query 3 | name: work 4 | required: true 5 | description: 佛典編號 6 | schema: 7 | type: string 8 | example: T0001 9 | juan: 10 | in: query 11 | name: juan 12 | required: true 13 | description: 卷號 14 | schema: 15 | type: integer 16 | example: 1 17 | work_info: 18 | in: query 19 | name: work_info 20 | required: false 21 | description: | 22 | 是否一併回傳「佛典資訊」 23 | 24 | * 預設為 0: 不回傳 25 | * 若設為 1: 回傳 26 | schema: 27 | type: integer 28 | example: 1 29 | toc: 30 | in: query 31 | name: toc 32 | required: false 33 | description: | 34 | 是否一併回傳目次 35 | 36 | * 預設為 0: 不回傳 37 | * 若設為 1: 回傳 38 | schema: 39 | type: integer 40 | example: 1 41 | -------------------------------------------------------------------------------- /public/api-docs/juans/response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found 6 | example: 1 7 | uuid: 8 | type: string 9 | description: Juan's UUID 10 | content: 11 | type: string 12 | description: Juan content's UUID 13 | results: 14 | type: array 15 | description: list of result 16 | items: 17 | type: string 18 | description: Juan's content in HTML format. 參考: [HTML for UI 格式說明](https://cbdata.dila.edu.tw/stable/static_pages/html_for_ui)。 19 | -------------------------------------------------------------------------------- /public/api-docs/lines/_.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: text lines 3 | tags: [line] 4 | description: | 5 | 使用範例: 6 | 7 | * 取得某行文字 /lines?linehead=T01n0001_p0001a04 8 | * 取得某行,以及前2行,後3行: /lines?linehead=T01n0001_p0001a09&before=2&after=3 9 | * 取得某段行號起迄範圍內文字: /lines?linehead_start=T01n0001_p0001a04&linehead_end=T01n0001_p0001a05 10 | * 跨卷也沒問題: /lines?linehead_start=T01n0001_p0011a01&linehead_end=T01n0001_p0011a06 11 | parameters: 12 | - $ref: parameters.yaml#/linehead 13 | - $ref: parameters.yaml#/before 14 | - $ref: parameters.yaml#/after 15 | - $ref: parameters.yaml#/linehead_start 16 | - $ref: parameters.yaml#/linehead_end 17 | responses: 18 | '200': 19 | description: text lines. 20 | content: 21 | application/json: 22 | schema: 23 | $ref: response.yaml 24 | -------------------------------------------------------------------------------- /public/api-docs/lines/parameters.yaml: -------------------------------------------------------------------------------- 1 | linehead: 2 | in: query 3 | name: linehead 4 | required: false 5 | description: CBETA 行首資訊 6 | example: T01n0001_p0001a04 7 | schema: 8 | type: string 9 | before: 10 | in: query 11 | name: before 12 | required: false 13 | description: 指定包含前面的幾行 14 | example: 2 15 | schema: 16 | type: integer 17 | after: 18 | in: query 19 | name: after 20 | required: false 21 | description: 指定包含後面的幾行 22 | example: 2 23 | schema: 24 | type: integer 25 | linehead_start: 26 | in: query 27 | name: linehead_start 28 | required: false 29 | description: 行首資訊 開始 30 | example: T01n0001_p0001a04 31 | schema: 32 | type: string 33 | linehead_end: 34 | in: query 35 | name: linehead_end 36 | required: false 37 | description: 行首資訊 開始 38 | example: T01n0001_p0001a05 39 | schema: 40 | type: string 41 | -------------------------------------------------------------------------------- /public/api-docs/lines/response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found 6 | example: 1 7 | results: 8 | type: array 9 | description: list of result 10 | items: 11 | type: object 12 | properties: 13 | linehead: 14 | type: string 15 | description: 行首資訊 16 | html: 17 | type: string 18 | description: text line in HTML format 19 | notes: 20 | type: object 21 | description: 校注。key 是校注編號,value 是校注內容。 22 | -------------------------------------------------------------------------------- /public/api-docs/search/_.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Full Text Search 3 | tags: [search] 4 | parameters: 5 | - in: query 6 | name: q 7 | required: true 8 | description: | 9 | 要搜尋的字詞,可以包含組字式。 10 | 11 | 例如 《新集藏經音義隨函錄(第13卷-第30卷)》卷17:「[幻-ㄠ+糸]術」(CBETA, K35, no. 1257, p. 189b6), 組字式 escape 之後:`[幻-ㄠ%2B糸]` 12 | 13 | 查詢 URL: `q=[幻-ㄠ%2B糸]` 14 | example: 法鼓 15 | schema: 16 | type: string 17 | - $ref: parameters.yaml#/fields 18 | responses: 19 | '200': 20 | description: search results. 21 | content: 22 | application/json: 23 | schema: 24 | $ref: response.yaml 25 | -------------------------------------------------------------------------------- /public/api-docs/search/all_in_one.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Full Text Search 3 | tags: [search] 4 | description: | 5 | 全文檢索並一次回傳 CBETA Online 前端所需的各種資料: 6 | 7 | * 一併回傳 KWIC (Keyword in Context) 8 | * 可選擇是否連同 facet 一起回傳。 9 | * 分頁以卷為單位。 10 | parameters: 11 | - $ref: parameters.yaml#/all_in_one_q 12 | - $ref: parameters.yaml#/note 13 | - $ref: parameters-filter.yaml#/category 14 | - $ref: parameters-filter.yaml#/canon 15 | - $ref: parameters-filter.yaml#/work 16 | - $ref: parameters-filter.yaml#/works 17 | - $ref: parameters-filter.yaml#/creator 18 | - $ref: parameters-filter.yaml#/dynasty 19 | - $ref: parameters-filter.yaml#/time 20 | - $ref: parameters-filter.yaml#/work_type 21 | - $ref: parameters-option.yaml#/facet 22 | - $ref: parameters.yaml#/puncs 23 | - $ref: parameters.yaml#/start 24 | - $ref: parameters.yaml#/rows 25 | - $ref: parameters.yaml#/order 26 | responses: 27 | '200': 28 | description: search results. 29 | content: 30 | application/json: 31 | schema: 32 | $ref: response.yaml 33 | -------------------------------------------------------------------------------- /public/api-docs/search/extended.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Search with Extended Query Syntax 3 | tags: [search] 4 | description: 全文檢索 (擴充模式) 5 | parameters: 6 | - $ref: parameters.yaml#/extended_q 7 | responses: 8 | '200': 9 | description: search results. 10 | content: 11 | application/json: 12 | schema: 13 | $ref: response.yaml 14 | -------------------------------------------------------------------------------- /public/api-docs/search/facet.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search 3 | tags: [search] 4 | description: 一次回傳五種 faceted search 結果: canon, category, dynasty, creator, work 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要搜尋的字詞。 10 | example: 法鼓 11 | schema: 12 | type: string 13 | responses: 14 | '200': 15 | description: search result 16 | content: 17 | application/json: 18 | schema: 19 | type: object 20 | properties: 21 | canon: 22 | type: array 23 | items: 24 | type: object 25 | category: 26 | type: array 27 | items: 28 | type: object 29 | creator: 30 | type: array 31 | items: 32 | type: object 33 | dynasty: 34 | type: array 35 | items: 36 | type: object 37 | work: 38 | type: array 39 | items: 40 | type: object 41 | -------------------------------------------------------------------------------- /public/api-docs/search/facet_canon.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search by 藏經 ID 3 | tags: [search] 4 | parameters: 5 | - name: q 6 | in: query 7 | required: true 8 | description: 要搜尋的字詞。 9 | example: 法鼓 10 | schema: 11 | type: string 12 | responses: 13 | '200': 14 | description: search result 15 | content: 16 | application/json: 17 | schema: 18 | type: array 19 | items: 20 | type: object 21 | properties: 22 | canon: 23 | type: string 24 | description: 藏經 ID 25 | example: T 26 | docs: 27 | type: integer 28 | description: number fo matched documents (卷/篇章) 29 | example: 382 30 | hits: 31 | type: integer 32 | description: number fo keyword occurences 33 | example: 569 34 | canon_name: 35 | type: string 36 | description: 藏經名稱 37 | example: 大正新脩大藏經 38 | -------------------------------------------------------------------------------- /public/api-docs/search/facet_category.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search by Category (CBETA 部類) 3 | tags: [search] 4 | description: "note: 一部佛典可能屬於多個部類。" 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要搜尋的字詞。 10 | example: 法鼓 11 | schema: 12 | type: string 13 | responses: 14 | '200': 15 | description: search result 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | type: object 22 | properties: 23 | category_id: 24 | type: integer 25 | example: 17 26 | docs: 27 | type: integer 28 | description: number fo matched documents (卷/篇章) 29 | example: 382 30 | hits: 31 | type: integer 32 | description: number fo keyword occurences 33 | example: 569 34 | category_name: 35 | type: string 36 | example: 禪宗部類 37 | -------------------------------------------------------------------------------- /public/api-docs/search/facet_creator.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search by Creator ID 3 | tags: [search] 4 | description: 根據作譯者 ID。 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要搜尋的字詞。 10 | example: 法鼓 11 | schema: 12 | type: string 13 | responses: 14 | '200': 15 | description: search result 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | type: object 22 | properties: 23 | creator_id: 24 | type: string 25 | example: A001519 26 | docs: 27 | type: integer 28 | description: number fo matched documents (卷/篇章) 29 | example: 382 30 | hits: 31 | type: integer 32 | description: number fo keyword occurences 33 | example: 569 34 | creator_name: 35 | type: string 36 | example: 道宣 37 | -------------------------------------------------------------------------------- /public/api-docs/search/facet_dynasty.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search by Dynasty (朝代) 3 | tags: [search] 4 | description: 根據佛典成立的朝代。 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要搜尋的字詞。 10 | example: 法鼓 11 | schema: 12 | type: string 13 | responses: 14 | '200': 15 | description: search result 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | type: object 22 | properties: 23 | dynasty: 24 | type: string 25 | example: 清 26 | docs: 27 | type: integer 28 | description: number fo matched documents (卷/篇章) 29 | example: 382 30 | hits: 31 | type: integer 32 | description: number fo keyword occurences 33 | example: 569 34 | -------------------------------------------------------------------------------- /public/api-docs/search/facet_work.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Faceted Search by Work 3 | tags: [search] 4 | description: 根據佛典。 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要搜尋的字詞。 10 | example: 法鼓 11 | schema: 12 | type: string 13 | responses: 14 | '200': 15 | description: search result 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | type: object 22 | properties: 23 | work: 24 | type: string 25 | description: 佛典編號 (經號) 26 | example: B0088 27 | docs: 28 | type: integer 29 | description: number fo matched documents (卷/篇章) 30 | example: 382 31 | hits: 32 | type: integer 33 | description: number fo keyword occurences 34 | example: 569 35 | title: 36 | type: string 37 | description: 佛典標題 (經名) 38 | example: 古今圖書集成選輯(上) 39 | -------------------------------------------------------------------------------- /public/api-docs/search/footnotes.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Search Footnotes 3 | tags: [search] 4 | parameters: 5 | - $ref: parameters.yaml#/extended_q 6 | - $ref: parameters.yaml#/start 7 | - $ref: parameters.yaml#/rows 8 | - $ref: parameters-filter.yaml#/category 9 | - $ref: parameters-filter.yaml#/canon 10 | - $ref: parameters-filter.yaml#/work 11 | - $ref: parameters-filter.yaml#/works 12 | - $ref: parameters-filter.yaml#/creator 13 | - $ref: parameters-filter.yaml#/dynasty 14 | - $ref: parameters-filter.yaml#/time 15 | - $ref: parameters-filter.yaml#/work_type 16 | - $ref: parameters-option.yaml#/facet 17 | responses: 18 | '200': 19 | description: search results. 20 | content: 21 | application/json: 22 | schema: 23 | $ref: footnotes-response.yaml 24 | -------------------------------------------------------------------------------- /public/api-docs/search/kwic-parameters.yaml: -------------------------------------------------------------------------------- 1 | - in: query 2 | name: work 3 | required: true 4 | description: 佛典編號,限制搜尋範圍在某部佛典之中。 5 | example: X0600 6 | schema: 7 | type: string 8 | - in: query 9 | name: juan 10 | required: true 11 | description: 卷號 12 | example: 11 13 | schema: 14 | type: integer 15 | - in: query 16 | name: q 17 | required: true 18 | description: 要搜尋的關鍵字,多個關鍵字以半形逗點區隔。 19 | example: 法鼓,聖嚴 20 | schema: 21 | type: string 22 | -------------------------------------------------------------------------------- /public/api-docs/search/kwic-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found kwics 6 | example: 2 7 | results: 8 | type: array 9 | description: list of kwics 10 | items: 11 | type: object 12 | properties: 13 | lb: 14 | type: string 15 | description: 行號 16 | example: 0216b12 17 | kwic: 18 | type: string 19 | description: 關鍵字前後文。 20 | example: 福。自非大聖嚴旨。安能信" -------------------------------------------------------------------------------- /public/api-docs/search/kwic.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 單卷 KeyWord In Context 3 | tags: [search] 4 | description: |- 5 | 搜尋,並傳回前後文。只限單卷。 6 | 7 | 夾注不列入搜尋範圍,以達成「跨夾注檢索」的目的。例如「差(音雌)別」,搜尋「差別」會找到。 8 | 9 | 回傳前後文(kwic 欄位)會含夾注,15字以上會節略,例如:「法無諍三昧法門上卷(云如⋯中略6618字⋯解脫)按從初𤼵心至成佛道一身」。 10 | parameters: 11 | $ref: kwic-parameters.yaml 12 | responses: 13 | '200': 14 | description: search result. 15 | content: 16 | application/json: 17 | schema: 18 | $ref: kwic-response.yaml 19 | -------------------------------------------------------------------------------- /public/api-docs/search/parameters-option.yaml: -------------------------------------------------------------------------------- 1 | facet: 2 | name: facet 3 | in: query 4 | required: false 5 | example: 1 6 | schema: 7 | type: integer 8 | enum: [0, 1] 9 | default: 0 10 | description: | 11 | 0: 不回傳 facet。 12 | 13 | 1: 回傳五種 facet: 藏經 (canon)、部類 (category)、作譯者 (creator)、朝代 (dynasty)、佛典 (work)。 14 | cache: 15 | in: query 16 | name: cache 17 | description: "指定是否使用 cache. 1: 使用 cache; 0: 不使用 cache." 18 | schema: 19 | type: integer 20 | enum: [0, 1] 21 | default: 1 22 | -------------------------------------------------------------------------------- /public/api-docs/search/sc.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 以簡體字搜尋 CBETA 3 | tags: [search] 4 | description: 使用 OpenCC 將簡體轉為繁體,再做搜尋,並回傳筆數。 5 | parameters: 6 | - name: q 7 | in: query 8 | required: true 9 | description: 要轉換的字詞。 10 | schema: 11 | type: string 12 | examples: 13 | ex1: 14 | value: 四圣谛 15 | summary: 四圣谛 會先轉為 四聖諦 16 | ex2: 17 | value: 上烏 18 | summary: "繁簡相同,回傳 hits: 0" 19 | responses: 20 | '200': 21 | description: 轉換後的繁體中文,以及 CBETA 中出現的筆數。 22 | content: 23 | application/json: 24 | schema: 25 | type: object 26 | properties: 27 | q: 28 | type: string 29 | description: 轉換後的繁體中文 30 | example: 四聖諦 31 | hits: 32 | type: integer 33 | description: CBETA 中出現的筆數 34 | example: 2860 35 | -------------------------------------------------------------------------------- /public/api-docs/search/semantic-response.yaml: -------------------------------------------------------------------------------- 1 | chunks: 2 | type: array 3 | minItems: 30 4 | maxItems: 30 5 | items: 6 | type: object 7 | properties: 8 | chunk_id: 9 | type: string 10 | example: d2_20 11 | work: 12 | type: string 13 | example: T25n1505 14 | linehead: 15 | type: string 16 | example: T25n1505_p0003c29 17 | text: (highlight) 18 | type: string 19 | example: 答:彼世間、出世間解脫,得是行必定解脫。是輩中間聖諦可得。如人度空野地,見園宅菓樹花實,彼意必定為不復飢餓、為近城郭。如思因緣為曠野地,婬怒癡為勞,善知識將導思惟,疾行陰界處,無常無我苦所有觀。若欲是有忍(三忍)。增思惟不動,如夢中見樂、見其形像。苦時相見是想增,世間最好法。世尊想如是,是禪。行其中間覺見喜,見聖諦。時婆素跋陀(秦言今賢,人名也,得無著道)三法解脫度。初說㗫未都(盡也,天竺品題皆在品後也)。 20 | reason: 21 | type: string 22 | description: AI 給出 符合的理由 23 | summary: 24 | type: string 25 | description: AI 根據 chunks 做出摘要。 26 | related_questions: 27 | description: AI 根據 Query string 提供相關問題。 28 | type: array 29 | minItems: 5 30 | maxItems: 5 31 | items: 32 | type: string 33 | -------------------------------------------------------------------------------- /public/api-docs/search/semantic.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 語意搜尋 (experimental) 3 | tags: [search] 4 | parameters: 5 | - in: query 6 | name: q 7 | required: true 8 | description: Query string. 9 | schema: 10 | type: string 11 | example: 如何修行能得解脫? 12 | - in: query 13 | name: model 14 | default: gpt-4o-mini 15 | - in: query 16 | name: api_key 17 | required: true 18 | - in: query 19 | name: llm 20 | description: |- 21 | 是否由 LLM 提供 理由、摘要、相關問題。
22 | 0: No; 1: Yes. 23 | schema: 24 | type: integer 25 | enum: [0, 1] 26 | default: 0 27 | responses: 28 | '200': 29 | content: 30 | application/json: 31 | schema: 32 | type: object 33 | properties: 34 | $ref: semantic-response.yaml 35 | -------------------------------------------------------------------------------- /public/api-docs/search/similar-parameters.yaml: -------------------------------------------------------------------------------- 1 | q: 2 | in: query 3 | name: q 4 | required: true 5 | description: 要搜尋的文字片段。 6 | schema: 7 | type: string 8 | examples: 9 | ex1: 10 | value: 已得善提捨不證 11 | ex2: 12 | value: 菩薩清涼月,遊於畢竟空,垂光照三界,心法無不現。 13 | ex3: 14 | value: 諸惡莫作,眾善奉行,自淨其意,是諸佛教 15 | ex4: 16 | value: 斷愛欲,轉諸結,慢無間等,究竟苦邊 17 | ex5: 18 | value: 若人欲了知,三世一切佛,應觀法界性,一切唯心造 19 | ex6: 20 | value: 是日已過,命亦隨減,如少水魚,斯有何樂 21 | k: 22 | in: query 23 | name: k 24 | description: 第一階段使用 Manticore 模糊搜尋,取 top k 筆數。 25 | schema: 26 | type: integer 27 | default: 500 28 | gain: 29 | in: query 30 | name: gain 31 | description: Smith-Waterman 演算法執行時,match 時的加分. 32 | schema: 33 | type: integer 34 | minimum: 0 35 | default: 2 36 | penality: 37 | in: query 38 | name: penalty 39 | description: Smith-Waterman 演算法執行時,miss、insertion、deletion 的減分,必須 <= 0,預設為 -1. 40 | schema: 41 | type: integer 42 | maximum: 0 43 | default: -1 44 | score_min: 45 | in: query 46 | name: score_min 47 | description: Smith-Waterman Score 最小值. 48 | schema: 49 | type: integer 50 | default: 16 51 | -------------------------------------------------------------------------------- /public/api-docs/search/synonym.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 近義詞 (near synonym) 建議 3 | tags: [search] 4 | parameters: 5 | - name: q 6 | in: query 7 | required: true 8 | description: 要搜尋的字詞。 9 | example: 文殊師利 10 | schema: 11 | type: string 12 | responses: 13 | '200': 14 | description: search results. 15 | content: 16 | application/json: 17 | schema: 18 | type: object 19 | properties: 20 | num_found: 21 | type: integer 22 | description: number of suggestions 23 | example: 3 24 | results: 25 | type: array 26 | description: list of suggestions 27 | items: 28 | type: string 29 | example: ["滿殊尸利", "曼殊室利", "妙德", "妙首", "妙吉祥", "文殊", "妙吉祥菩薩", "妙音", "曼殊"] 30 | -------------------------------------------------------------------------------- /public/api-docs/search/title-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found works (符合的佛典筆數) 6 | example: 1 7 | results: 8 | type: array 9 | description: list of works 10 | items: 11 | type: object 12 | properties: 13 | work: 14 | type: string 15 | description: 佛典編號(經號) 16 | example: T0270 17 | title: 18 | type: string 19 | description: Work's Title 20 | example: 大法鼓經 21 | byline: 22 | type: string 23 | description: 作譯者行 24 | example: 劉宋 求那跋陀羅譯 25 | creators_with_id: 26 | type: string 27 | description: 作者、譯者 (含 DILA Authority 人名 ID) 28 | example: 求那跋陀羅(A000527) 29 | time_dynasty: 30 | type: string 31 | description: 佛典成立時間:朝代 32 | example: 劉宋 33 | time_from: 34 | type: integer 35 | description: 佛典成立時間:起始西元年 36 | example: 435 37 | time_to: 38 | type: integer 39 | description: 佛典成立時間:結束西元年 40 | example: 443 -------------------------------------------------------------------------------- /public/api-docs/search/title.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: Search Titles 3 | tags: [search] 4 | description: 搜尋佛典標題(經名) 5 | parameters: 6 | - $ref: parameters.yaml#/extended_q 7 | responses: 8 | '200': 9 | description: search results. 10 | content: 11 | application/json: 12 | schema: 13 | $ref: title-response.yaml 14 | -------------------------------------------------------------------------------- /public/api-docs/search/variants-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of suggestions 6 | example: 3 7 | results: 8 | type: array 9 | description: list of suggestions 10 | items: 11 | type: object 12 | properties: 13 | q: 14 | type: string 15 | description: variant term 16 | example: 著衣持盋 17 | hits: 18 | type: integer 19 | description: q 在 CBETA 中出現的次數 20 | example: 3 -------------------------------------------------------------------------------- /public/api-docs/search/variants.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 異體字建議 3 | tags: [search] 4 | description: |- 5 | # 資料來源 6 | * 感謝 [國家教育研究院](https://www.naer.edu.tw/) 授權 [法鼓文理學院](http://www.dila.edu.tw/) 使用 教育部[《異體字字典》](https://dict.variants.moe.edu.tw/variants)、《異形詞辨析手冊》。 7 | * 開放資料: 8 | parameters: 9 | - name: q 10 | in: query 11 | required: true 12 | description: 要搜尋的字詞。 13 | example: 著衣持鉢 14 | schema: 15 | type: string 16 | responses: 17 | '200': 18 | description: search results. 19 | content: 20 | application/json: 21 | schema: 22 | $ref: variants-response.yaml 23 | -------------------------------------------------------------------------------- /public/api-docs/word_seg/_.yaml: -------------------------------------------------------------------------------- 1 | post: 2 | summary: DILA 佛典自動分詞 測試版 3 | tags: [tool] 4 | description: | 5 | * 使用 CRF++ 自動分詞 6 | * 不支援咒語。 7 | * 使用半形斜線做為分詞區隔符號。 8 | requestBody: 9 | required: true 10 | content: 11 | application/x-www-form-urlencoded: 12 | schema: 13 | type: object 14 | properties: 15 | t: 16 | type: string 17 | required: 18 | - t 19 | example: 20 | t: "當觀色無常。如是觀者,則為正觀。正觀者,則生厭離;厭離者,喜貪盡;喜貪盡者,說心解脫。" 21 | responses: 22 | '200': 23 | description: 分詞後結果 24 | content: 25 | text/plain: 26 | schema: 27 | type: string 28 | example: /當/觀/色/無常/。/如是/觀/者/,/則/為/正觀/。/正觀/者/,/則/生/厭離/;/厭離/者/,/喜/貪/盡/;/喜/貪/盡/者/,/說/心解脫/。/ 29 | -------------------------------------------------------------------------------- /public/api-docs/works/_.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 佛典相關資訊 3 | tags: [work] 4 | description: | 5 | 例: 6 | * 取得某部佛典的資訊, 取得 T0001 的資訊: /works?work=T0001 7 | * 指定冊數起迄: /works?canon=T&vol_start=1&vol_end=2 8 | * 指定經號起迄: /works?canon=T&work_start=1&work_end=2 9 | * 指定 嘉興藏 經號起迄: /works?canon=J&work_start=A1&work_end=A2 10 | * 以作譯者 ID 搜尋: /works?creator_id=A000439 11 | * 搜尋唐朝成立的佛典: /works?dynasty=唐 12 | * 搜尋多個朝代: /works?dynasty=符秦,前秦 13 | * 搜尋成立年代在公元 600年至700年之間的佛典: /works?time_start=600&time_end=700 14 | parameters: 15 | - $ref: parameters.yaml#/canon 16 | - $ref: parameters.yaml#/vol_start 17 | - $ref: parameters.yaml#/vol_end 18 | - $ref: parameters.yaml#/work_start 19 | - $ref: parameters.yaml#/work_end 20 | - $ref: parameters.yaml#/creator_id 21 | - $ref: parameters.yaml#/creator 22 | - $ref: parameters.yaml#/creator_name 23 | - $ref: parameters.yaml#/dynasty 24 | - $ref: parameters.yaml#/time_start 25 | - $ref: parameters.yaml#/time_end 26 | work: 27 | responses: 28 | '200': 29 | description: Works Information 30 | content: 31 | application/json: 32 | schema: 33 | $ref: response.yaml 34 | -------------------------------------------------------------------------------- /public/api-docs/works/toc-node.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | title: 4 | type: string 5 | description: 目次節點 標題 6 | example: 2 遊行經 7 | file: 8 | type: string 9 | description: 目次節點 所在 xml 檔 主檔名。 10 | example: T01n0001 11 | juan: 12 | type: integer 13 | description: 目次節點 所在卷號。 14 | example: 2 15 | lb: 16 | type: string 17 | description: 目次節點 所在 頁、欄、行。 18 | example: 0011a07 19 | type: 20 | type: string 21 | description: 例如 T0001 目次節點「2 遊行經」,回傳 type 為「經」。 22 | example: 經 23 | n: 24 | type: integer 25 | description: 例如 T0001 目次節點「2 遊行經」,回傳 n 為 2. 26 | example: 2 27 | isFolder: 28 | type: boolean 29 | description: 預設值為 false,若為 true,表示有 children. 30 | example: true 31 | children: 32 | type: array 33 | items: 34 | $ref: "" 35 | example: 36 | - title: "1" 37 | file: T01n0001 38 | juan: 2 39 | lb: "0011a07" 40 | n: 1 41 | - title: "2" 42 | file: T01n0001 43 | juan: 3 44 | lb: "0016b14" 45 | n: 2 46 | -------------------------------------------------------------------------------- /public/api-docs/works/toc-response.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | properties: 3 | num_found: 4 | type: integer 5 | description: number of found 6 | example: 1 7 | results: 8 | type: array 9 | description: 佛典內目次。 10 | items: 11 | type: object 12 | properties: 13 | mulu: 14 | type: array 15 | description: 目次 16 | items: 17 | $ref: "toc-node.yaml" 18 | juan: 19 | type: array 20 | description: 卷(篇章)目錄 21 | items: 22 | type: object 23 | properties: 24 | file: 25 | type: string 26 | juan: 27 | type: integer 28 | lb: 29 | type: string 30 | title: 31 | type: string 32 | example: 33 | - file: T01n0001 34 | juan: 1 35 | lb: "0001b08" 36 | title: 第一 37 | - file: T01n0001 38 | juan: 2 39 | lb: "0011a04" 40 | title: 第二 41 | -------------------------------------------------------------------------------- /public/api-docs/works/toc.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | summary: 目次 (Table of content) 3 | tags: [work] 4 | description: | 5 | 取得某部佛典內的目次、卷(篇章)目錄 6 | 7 | 例如取得 T0001 的目次: works/toc?work=T0001 8 | parameters: 9 | - work: 10 | name: work 11 | in: query 12 | required: false 13 | description: 佛典編號 14 | example: T0001 15 | schema: 16 | type: string 17 | responses: 18 | '200': 19 | description: | 20 | 佛典內目次。 21 | content: 22 | application/json: 23 | schema: 24 | $ref: 'toc-response.yaml' 25 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/public/favicon.ico -------------------------------------------------------------------------------- /public/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/public/icon.png -------------------------------------------------------------------------------- /public/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400] 5 | end 6 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/controllers/.keep -------------------------------------------------------------------------------- /test/controllers/catalog_entry_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CatalogEntryControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/chinese_tools_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ChineseToolsControllerTest < ActionDispatch::IntegrationTest 4 | test "should get sc2tc" do 5 | get chinese_tools_sc2tc_url 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /test/controllers/download_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DownloadControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/export_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ExportControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/juans_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class JuansControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/kwic_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class KwicControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/lines_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LinesControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/report_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ReportControllerTest < ActionDispatch::IntegrationTest 4 | test "should get access" do 5 | get report_daily_url 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /test/controllers/sphinx_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SphinxControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/static_pages_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class StaticPagesControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/toc_node_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TocNodeControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/word_seg_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class WordSegControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/works_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class WorksControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/fixtures/.keep -------------------------------------------------------------------------------- /test/fixtures/categories.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | 'n': 1 5 | name: MyString 6 | 7 | two: 8 | 'n': 1 9 | name: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/gaijis.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | cb: MyString 5 | zzs: MyString 6 | 7 | two: 8 | cb: MyString2 9 | zzs: MyString2 10 | -------------------------------------------------------------------------------- /test/fixtures/goto_abbrs.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | abbr: MyString 5 | ref: MyString 6 | 7 | two: 8 | abbr: MyString 9 | ref: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/juan_lines.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | vol: MyString 5 | work: MyString 6 | juan: 1 7 | lb: MyString 8 | 9 | two: 10 | vol: MyString 11 | work: MyString2 12 | juan: 1 13 | lb: MyString2 14 | -------------------------------------------------------------------------------- /test/fixtures/lines.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | linehead: MyString 5 | html: MyText 6 | notes: MyText 7 | 8 | two: 9 | linehead: MyString 10 | html: MyText 11 | notes: MyText 12 | -------------------------------------------------------------------------------- /test/fixtures/people.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | id2: MyString 5 | name: MyString 6 | 7 | two: 8 | id2: MyString 9 | name: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/terms.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | group_id: 1 5 | term: MyString 6 | 7 | two: 8 | group_id: 1 9 | term: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/toc_nodes.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | 'n': MyString 5 | label: MyString 6 | parent: MyString 7 | 8 | two: 9 | 'n': MyString 10 | label: MyString 11 | parent: MyString 12 | -------------------------------------------------------------------------------- /test/fixtures/variants.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | k: MyString 5 | vars: MyString 6 | 7 | two: 8 | k: MyString 9 | vars: MyString 10 | -------------------------------------------------------------------------------- /test/fixtures/works.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | one: {} 8 | # column: value 9 | # 10 | two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/xml_files.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | vol: MyString 5 | work: MyString 6 | file: MyString 7 | juan_start: 1 8 | juans: 1 9 | 10 | two: 11 | vol: MyString 12 | work: MyString 13 | file: MyString 14 | juan_start: 1 15 | juans: 1 16 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/helpers/.keep -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/integration/.keep -------------------------------------------------------------------------------- /test/integration/download_texts_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class DownloadTextsTest < ActionDispatch::IntegrationTest 4 | test "download text" do 5 | zip_file = Rails.root.join('data', "download/text/T2782.txt.zip") 6 | Zip::File.open(zip_file) do |z| 7 | text = z.read('T2782_001.txt').force_encoding('UTF-8') 8 | assert text.include?('覺不堅為堅  善住於顛倒'), "偈頌之間要空格, #{zip_file}" 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/test/models/.keep -------------------------------------------------------------------------------- /test/models/category_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CategoryTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/gaiji_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class GaijiTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/goto_abbr_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class GotoAbbrTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/juan_line_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class JuanLineTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/line_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LineTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/person_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PersonTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/term_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TermTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/toc_node_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TocNodeTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/variant_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class VariantTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/work_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class WorkTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/xml_file_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class XmlFileTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | #fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DILA-edu/cbeta-api/3ce567907d47952db7b383478923b7bfb0054154/vendor/assets/stylesheets/.keep --------------------------------------------------------------------------------