jeawin-astro 3.0.52 → 3.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jeawin-astro",
3
- "version": "3.0.52",
3
+ "version": "3.0.53",
4
4
  "author": "chaegumi <chaegumi@qq.com>",
5
5
  "description": "",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@ import { render_value, render_lang } from "../scripts/util.js";
12
12
  import Input from "./formitem/input.astro";
13
13
  const { btn_class, siteinfo, jeawin_form_api_domain, all_langs } = Astro.locals;
14
14
 
15
- const {other_btn_class} = Astro.props;
15
+ const {other_btn_class, max_width = 'max-w-md'} = Astro.props;
16
16
  ---
17
17
 
18
18
  <form
@@ -24,7 +24,7 @@ const {other_btn_class} = Astro.props;
24
24
  <input type="hidden" name="site_id" value={siteinfo.id} />
25
25
  <input type="hidden" name="captchaId" id="captchaIdSubscribe" value="" />
26
26
  <input type="hidden" name="captcha_code" id="captchaCodeSubscribe" value="" />
27
- <div class="max-w-md">
27
+ <div class:list={max_width}>
28
28
  <div class="flex flex-wrap gap-2 -mx-2">
29
29
  <div class="px-2 grow-[9999] basis-64">
30
30
  <Input
@@ -46,3 +46,7 @@ export function render_lang(all_langs: any, key: any): any;
46
46
  * 去除内容中的toc
47
47
  */
48
48
  export function without_toc(content: any): string;
49
+ /**
50
+ * 显示视频栏目内容
51
+ */
52
+ export function render_video_content(content: any, picurl: any, node_title: any): string;
@@ -354,4 +354,97 @@ export function without_toc(content){
354
354
  $('script')?.remove();
355
355
  $('.toc-anchor')?.remove();
356
356
  return $.html();
357
- }
357
+ }
358
+
359
+ /**
360
+ * 显示视频栏目内容
361
+ */
362
+ export function render_video_content(content, picurl, node_title){
363
+
364
+ let return_html = '';
365
+
366
+ const $ = cheerio.load(content);
367
+
368
+ const iframes = $('iframe');
369
+
370
+ let hasVideo = false;
371
+
372
+ iframes.each(function(i, elem){
373
+ const src = $(this).attr('src');
374
+ // console.log(src);
375
+ if(src.indexOf('youtube')!== -1 || src.indexOf('vimeo') !== -1){
376
+ // 是视频
377
+ hasVideo = true;
378
+ // 修改元素
379
+ $(this).wrap(`<div class="video-wrapper">
380
+ <img src="${picurl}" alt="${node_title}" class="video-poster">
381
+ <button class="play-button" type="button">▶</button>
382
+ <iframe src="" data-src="${src}"
383
+ allowfullscreen class="video-frame" title="${node_title}" width="100%" height="100%"></iframe>
384
+ </div>`);
385
+
386
+ }
387
+ });
388
+
389
+ return_html = $.html();
390
+ // console.log(return_html);
391
+
392
+ if(hasVideo){
393
+ // 包含视频
394
+ return_html += `<style>
395
+ .video-wrapper {
396
+ position: relative;
397
+ width: 100%;
398
+ max-width: 800px;
399
+ aspect-ratio: 16/9;
400
+ margin:0 auto;
401
+ }
402
+
403
+ .video-poster {
404
+ width: 100%;
405
+ height: 100%;
406
+ object-fit: contain;
407
+ }
408
+
409
+ .play-button {
410
+ position: absolute;
411
+ top: 50%;
412
+ left: 50%;
413
+ transform: translate(-50%, -50%);
414
+ width: 80px;
415
+ height: 80px;
416
+ border-radius: 50%;
417
+ background: rgba(255, 0, 0, 0.8);
418
+ border: none;
419
+ color: white;
420
+ font-size: 24px;
421
+ cursor: pointer;
422
+ z-index: 1;
423
+ }
424
+
425
+ .video-frame {
426
+ position: absolute;
427
+ width: 100%;
428
+ height: 100%;
429
+ top: 0;
430
+ left: 0;
431
+ display: none;
432
+ }
433
+ </style>
434
+
435
+ <script>
436
+ document.querySelector('.play-button').addEventListener('click', function() {
437
+ const wrapper = this.parentElement;
438
+ const iframe = wrapper.querySelector('.video-frame');
439
+ const poster = wrapper.querySelector('.video-poster');
440
+
441
+ iframe.src = iframe.dataset.src;
442
+ iframe.style.display = 'block';
443
+ poster.style.display = 'none';
444
+ this.style.display = 'none';
445
+ });
446
+ </script>`;
447
+ }
448
+
449
+ return return_html;
450
+ }