feat: support to links in changelog

This commit is contained in:
Fabio Di Stasio 2023-08-08 18:05:27 +02:00
parent 8c4c93cb07
commit ad7e459c68
1 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import { marked } from 'marked';
import BaseLoader from '@/components/BaseLoader.vue'; import BaseLoader from '@/components/BaseLoader.vue';
import { useApplicationStore } from '@/stores/application'; import { useApplicationStore } from '@/stores/application';
import { ref } from 'vue'; import { ref } from 'vue';
import { shell } from 'electron';
const { appVersion } = useApplicationStore(); const { appVersion } = useApplicationStore();
@ -26,6 +27,10 @@ const isLoading = ref(true);
const error = ref(''); const error = ref('');
const isError = ref(false); const isError = ref(false);
const openOutside = (link: string) => {
shell.openExternal(link);
};
const getChangelog = async () => { const getChangelog = async () => {
try { try {
const apiRes = await fetch(`https://api.github.com/repos/antares-sql/antares/releases/tags/v${appVersion}`, { const apiRes = await fetch(`https://api.github.com/repos/antares-sql/antares/releases/tags/v${appVersion}`, {
@ -40,7 +45,7 @@ const getChangelog = async () => {
const renderer = { const renderer = {
link (href: string, title: string, text: string) { link (href: string, title: string, text: string) {
return text; return `<a class="changelog-link" href="${href}" title="${title || ''}" target="_blank">${text}</a>`;
}, },
listitem (text: string) { listitem (text: string) {
return `<li>${text.replace(/ *\([^)]*\) */g, '')}</li>`; return `<li>${text.replace(/ *\([^)]*\) */g, '')}</li>`;
@ -57,6 +62,17 @@ const getChangelog = async () => {
} }
isLoading.value = false; isLoading.value = false;
setTimeout(() => {
const links = document.querySelectorAll<HTMLAnchorElement>('.changelog-link');
for (const link of links) {
link.addEventListener('click', e => {
e.preventDefault();
openOutside(link.href);
});
}
}, 0);
}; };
getChangelog(); getChangelog();