nodebb-plugin-link-preview 1.1.0 → 1.1.2

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
@@ -4,6 +4,7 @@
4
4
  'use strict';
5
5
 
6
6
  const winston = require.main.require('winston');
7
+ const nconf = require.main.require('nconf');
7
8
  const dns = require('dns');
8
9
 
9
10
  const { getLinkPreview } = require('link-preview-js');
@@ -53,13 +54,18 @@ async function process(content, opts) {
53
54
  const $anchor = $(anchor);
54
55
 
55
56
  // Skip if the anchor has link text, or has text on the same line.
56
- const url = $anchor.attr('href');
57
+ let url = $anchor.attr('href');
57
58
  const text = $anchor.text();
58
59
  const hasSiblings = !!anchor.prev || !!anchor.next;
59
60
  if (hasSiblings || url !== text) {
60
61
  continue;
61
62
  }
62
63
 
64
+ // Handle relative URLs
65
+ if (!url.startsWith('http')) {
66
+ url = `${nconf.get('url')}${url.startsWith('/') ? url : `/${url}`}`;
67
+ }
68
+
63
69
  const special = await handleSpecialEmbed(url, $anchor);
64
70
  if (special) {
65
71
  continue;
@@ -67,8 +73,9 @@ async function process(content, opts) {
67
73
 
68
74
  const cached = cache.get(`link-preview:${url}`);
69
75
  if (cached) {
70
- if (cached.contentType) {
71
- $anchor.replaceWith($(await render(cached)));
76
+ const html = await render(cached);
77
+ if (html) {
78
+ $anchor.replaceWith($(html));
72
79
  }
73
80
  continue;
74
81
  }
@@ -107,13 +114,18 @@ async function process(content, opts) {
107
114
  winston.verbose(`[link-preview] ${preview.url} (${preview.contentType}, cache: miss)`);
108
115
  cache.set(`link-preview:${url}`, preview);
109
116
 
117
+ const html = await render(preview);
118
+ if (!html) {
119
+ return;
120
+ }
121
+
110
122
  // bust posts cache item
111
123
  if (opts.hasOwnProperty('pid') && await posts.exists(opts.pid)) {
112
124
  postsCache.del(String(opts.pid));
113
125
 
114
126
  // fire post edit event with mocked data
115
127
  if (opts.hasOwnProperty('tid') && await topics.exists(opts.tid)) {
116
- $anchor.replaceWith($(await render(preview)));
128
+ $anchor.replaceWith($(html));
117
129
  websockets.in(`topic_${opts.tid}`).emit('event:post_edited', {
118
130
  post: {
119
131
  tid: opts.tid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-link-preview",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A starter kit for quickly creating NodeBB plugins",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -2,7 +2,9 @@
2
2
  {{{ if images.length }}}
3
3
  {{{ each images }}}
4
4
  {{{ if @first }}}
5
- <img src="{@value}" class="card-img-top not-responsive" style="max-height: 15rem;" />
5
+ <a href="{url}">
6
+ <img src="{@value}" class="card-img-top not-responsive" style="max-height: 15rem;" />
7
+ </a>
6
8
  {{{ end }}}
7
9
  {{{ end }}}
8
10
  {{{ end }}}
@@ -1 +1,3 @@
1
- <iframe src="https://player.vimeo.com/video/{video}?h=65e20fad6f&title=0&byline=0&portrait=0" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
1
+ <div class="ratio ratio-16x9">
2
+ <iframe src="https://player.vimeo.com/video/{video}?h=65e20fad6f&title=0&byline=0&portrait=0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
3
+ </div>
@@ -1 +1,3 @@
1
- <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/{video}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
1
+ <div class="ratio ratio-16x9">
2
+ <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>
3
+ </div>