nodebb-plugin-link-preview 1.1.2 → 1.2.1

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/library.js CHANGED
@@ -178,16 +178,20 @@ async function render(preview) {
178
178
  async function handleSpecialEmbed(url, $anchor) {
179
179
  const { app } = require.main.require('./src/webserver');
180
180
  const { hostname, searchParams, pathname } = new URL(url);
181
- const { embedYoutube, embedVimeo } = await meta.settings.get('link-preview');
181
+ const { embedYoutube, embedVimeo, embedTiktok } = await meta.settings.get('link-preview');
182
182
 
183
183
  if (embedYoutube === 'on' && ['youtube.com', 'www.youtube.com', 'youtu.be'].some(x => hostname === x)) {
184
184
  let video;
185
+ let short = false;
185
186
  if (hostname === 'youtu.be') {
186
187
  video = pathname.slice(1);
188
+ } else if (pathname.startsWith('/shorts')) {
189
+ video = pathname.split('/')[2];
190
+ short = true;
187
191
  } else {
188
192
  video = searchParams.get('v');
189
193
  }
190
- const html = await app.renderAsync('partials/link-preview/youtube', { video });
194
+ const html = await app.renderAsync(short ? 'partials/link-preview/youtube-short' : 'partials/link-preview/youtube', { video });
191
195
  $anchor.replaceWith(html);
192
196
 
193
197
  return true;
@@ -201,6 +205,14 @@ async function handleSpecialEmbed(url, $anchor) {
201
205
  return true;
202
206
  }
203
207
 
208
+ if (embedTiktok === 'on' && ['tiktok.com', 'www.tiktok.com'].some(x => hostname === x)) {
209
+ const video = pathname.split('/')[3];
210
+ const html = await app.renderAsync('partials/link-preview/tiktok', { video });
211
+ $anchor.replaceWith(html);
212
+
213
+ return true;
214
+ }
215
+
204
216
  return false;
205
217
  }
206
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-link-preview",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "A starter kit for quickly creating NodeBB plugins",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -54,6 +54,11 @@
54
54
  <input type="checkbox" class="form-check-input" id="embedVimeo" name="embedVimeo">
55
55
  <label for="embedVimeo" class="form-check-label">Vimeo</label>
56
56
  </div>
57
+
58
+ <div class="form-check form-switch mb-3">
59
+ <input type="checkbox" class="form-check-input" id="embedTiktok" name="embedTiktok">
60
+ <label for="embedTiktok" class="form-check-label">Vimeo</label>
61
+ </div>
57
62
  </div>
58
63
  </form>
59
64
  </div>
@@ -0,0 +1,3 @@
1
+ <div class="ratio" style="--bs-aspect-ratio: 177%;">
2
+ <iframe src="https://www.tiktok.com/embed/v2/{video}" title="TikTok video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
3
+ </div>
@@ -0,0 +1,5 @@
1
+ <div class="col-sm-6">
2
+ <div class="ratio" style="--bs-aspect-ratio: 177%;">
3
+ <iframe src="https://www.youtube-nocookie.com/embed/{video}" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
4
+ </div>
5
+ </div>