Skip to content

Commit

Permalink
feat: 初步完成
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed May 5, 2024
1 parent 7977a9c commit e783ea7
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 63 deletions.
2 changes: 0 additions & 2 deletions .discourse-compatibility

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **Plugin Name** Plugin
# Discourse Onebox Bilibili Plugin

**Plugin Summary**

For more information, please see: **url to meta topic**
Add support for Bilibili video embeds in Discourse.
Empty file removed app/.gitkeep
Empty file.
11 changes: 0 additions & 11 deletions app/controllers/my_plugin_module/examples_controller.rb

This file was deleted.

Empty file removed assets/javascripts/.gitkeep
Empty file.
Empty file removed assets/stylesheets/.gitkeep
Empty file.
9 changes: 0 additions & 9 deletions config/locales/client.en.yml

This file was deleted.

1 change: 0 additions & 1 deletion config/locales/server.en.yml

This file was deleted.

8 changes: 0 additions & 8 deletions config/routes.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/settings.yml

This file was deleted.

Empty file removed db/.gitkeep
Empty file.
13 changes: 0 additions & 13 deletions lib/my_plugin_module/engine.rb

This file was deleted.

50 changes: 37 additions & 13 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
# frozen_string_literal: true

# name: discourse-plugin-name
# about: TODO
# meta_topic_id: TODO
# version: 0.0.1
# authors: Discourse
# url: TODO
# name: discourse-onebox-bilibili
# about: Add support for Bilibili video embeds in Discourse
# version: 1.0.0
# authors: TreeNewBee
# url: https://github.com/TheTNB/discourse-onebox-bilibili
# required_version: 2.7.0

enabled_site_setting :plugin_name_enabled
require "onebox"

module ::MyPluginModule
PLUGIN_NAME = "discourse-plugin-name"
end
class Onebox::Engine::BilibiliOnebox
include Onebox::Engine

matches_regexp(/^https?:\/\/(?:www\.)?bilibili\.com\/video\/([a-zA-Z0-9]+)\/?$/)
always_https

def video_id
match = uri.path.match(/\/video\/av(\d+)(\.html)?.*/)
return "aid=#{match[1]}" if match && match[1]
match = uri.path.match(/\/video\/BV([a-zA-Z0-9]+)(\.html)?.*/)
return "bvid=#{match[1]}" if match && match[1]

nil
rescue
return nil
end

require_relative "lib/my_plugin_module/engine"
def to_html
<<-HTML
<iframe
src='https://player.bilibili.com/player.html?#{video_id}&p=1'
frameborder="0"
framespacing="0"
width='100%'
style='aspect-ratio: 16/9;margin:auto;'
allowfullscreen>
</iframe>
HTML
end

after_initialize do
# Code which should run after Rails has finished booting
def placeholder_html
to_html
end
end
Empty file removed spec/.gitkeep
Empty file.
Empty file removed test/javascripts/.gitkeep
Empty file.

0 comments on commit e783ea7

Please sign in to comment.