mirror of
https://github.com/pinry/pinry.git
synced 2026-06-19 23:59:50 +02:00
Refactor niceLinks and add where missing.
Signed-off-by: Lapo Luchini <lapo@lapo.it>
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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
pinry-spa/src/components/utils/niceLinks.js
Normal file
13
pinry-spa/src/components/utils/niceLinks.js
Normal 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;
|
||||
Reference in New Issue
Block a user