Browse Source

Refactor `niceLinks` and add where missing.

Signed-off-by: Lapo Luchini <lapo@lapo.it>
tags/v2.0.2
Lapo Luchini 4 years ago
parent
commit
b8056e5f84
4 changed files with 21 additions and 13 deletions
  1. +4
    -1
      pinry-spa/src/components/PinPreview.vue
  2. +1
    -12
      pinry-spa/src/components/Pins.vue
  3. +3
    -0
      pinry-spa/src/components/pin_edit/PinCreateModal.vue
  4. +13
    -0
      pinry-spa/src/components/utils/niceLinks.js

+ 4
- 1
pinry-spa/src/components/PinPreview.vue View File

@@ -9,7 +9,7 @@
</div>
<div class="card-content">
<div class="content">
<p class="description title">{{ pinItem.description }}</p>
<p class="description title" v-html="niceLinks(pinItem.description)"></p>
</div>
<div class="media">
<div class="media-left">
@@ -60,6 +60,8 @@
</template>

<script>
import niceLinks from './utils/niceLinks';

export default {
name: 'PinPreview',
props: ['pinItem'],
@@ -70,6 +72,7 @@ export default {
{ name: 'pin', params: { pinId: this.pinItem.id } },
);
},
niceLinks,
},
};
</script>


+ 1
- 12
pinry-spa/src/components/Pins.vue View File

@@ -83,6 +83,7 @@ import noMore from './noMore.vue';
import scroll from './utils/scroll';
import bus from './utils/bus';
import EditorUI from './editors/PinEditorUI.vue';
import niceLinks from './utils/niceLinks';

function createImageItem(pin) {
const image = {};
@@ -126,18 +127,6 @@ function initialData() {
};
}

const encoder = document.createElement('div');
function escapeHTML(text) {
encoder.innerText = text;
return encoder.innerHTML;
}

const reURL = /https?:[/][/](?:www[.])?([^/]+)(?:[/]([.]?[^\s,.<>])+)?/g;
function niceLinks(text) {
if (!text) return '';
return escapeHTML(text).replace(reURL, '<a href="$&" target="_blank">$1</a>');
}

export default {
name: 'pins',
components: {


+ 3
- 0
pinry-spa/src/components/pin_edit/PinCreateModal.vue View File

@@ -13,6 +13,7 @@
v-on:imageUploadSucceed="onUploadDone"
v-on:imageUploadProcessing="onUploadProcessing"
></FileUpload>
<div class="description" v-show="pinModel.form.description.value" v-html="niceLinks(pinModel.form.description.value)"></div>
</div>
<div class="column">
<b-field label="Image URL"
@@ -109,6 +110,7 @@ import bus from '../utils/bus';
import ModelForm from '../utils/ModelForm';
import Loading from '../utils/Loading';
import AutoComplete from '../utils/AutoComplete';
import niceLinks from '../utils/niceLinks';

function isURLBlank(url) {
return url !== null && url === '';
@@ -271,6 +273,7 @@ export default {
},
);
},
niceLinks,
},
};
</script>

+ 13
- 0
pinry-spa/src/components/utils/niceLinks.js View File

@@ -0,0 +1,13 @@
const encoder = document.createElement('div');
function escapeHTML(text) {
encoder.innerText = text;
return encoder.innerHTML;
}

const reURL = /https?:[/][/](?:www[.])?([^/]+)(?:[/]([.]?[^\s,.<>])+)?/g;
function niceLinks(text) {
if (!text) return '';
return escapeHTML(text).replace(reURL, '<a href="$&" target="_blank">$1</a>');
}

export default niceLinks;

Loading…
Cancel
Save