1+ import luxon from 'luxon' ;
12import showdown from 'showdown' ;
23import axios from 'axios' ;
34import { scriptVersion } from 'src/utils/1.variables.js' ;
@@ -39,13 +40,6 @@ function getMarkdown() {
3940 }
4041 return changelog . markdown ;
4142}
42- function getAxios ( ) {
43- if ( ! changelog . axios ) {
44- // TODO: get from github?
45- changelog . axios = axios . create ( { baseURL : 'https://unpkg.com/' } ) ;
46- }
47- return changelog . axios ;
48- }
4943
5044function open ( message ) {
5145 BootstrapDialog . show ( {
@@ -61,25 +55,23 @@ function open(message) {
6155 } ) ;
6256}
6357
64- export function get ( version = 'latest' , short = false ) {
58+ export async function get ( version = 'latest' , short = false ) {
6559 const cache = version . includes ( '.' ) ;
6660 const key = `${ version } ${ short ? '_short' : '' } ` ;
6761 if ( cache && changelog [ key ] ) return Promise . resolve ( changelog [ key ] ) ;
6862
69- const extension = `underscript@${ version } /changelog.md` ;
70- return getAxios ( ) . get ( extension ) . then ( ( { data : text } ) => {
71- const first = text . indexOf ( `\n## ${ cache ? `Version ${ version } ` : '' } ` ) ;
72- let end ;
73- if ( ! ~ first ) throw new Error ( 'Invalid Changelog' ) ;
74- if ( short ) {
75- const index = text . indexOf ( '\n## ' , first + 1 ) ;
76- if ( index !== - 1 ) end = index ;
77- }
78- const parsedHTML = getMarkdown ( ) . makeHtml ( text . substring ( first , end ) . trim ( ) ) . replace ( / \r ? \n / g, '' ) ;
79- // Cache results
80- if ( cache ) changelog [ key ] = parsedHTML ;
81- return parsedHTML ;
82- } ) ;
63+ if ( version === 'latest' ) {
64+ const { data } = await axios . get ( 'https://raw.githubusercontent.com/UCProjects/UnderScript/refs/heads/master/changelog.md' ) ;
65+
66+ return getMarkdown ( ) . makeHtml ( data . substring ( data . indexOf ( '##' ) ) ) . replace ( / \r ? \n / g, '' ) ;
67+ }
68+
69+ const { data : { body : text , name, published_at : published } } = await axios . get ( `https://api.github.com/repos/UCProjects/UnderScript/releases/tags/${ version } }` ) ;
70+ const date = luxon . DateTime . fromISO ( published ) . toLocaleString ( luxon . DateTime . DATE_MED ) ;
71+ const parsedHTML = getMarkdown ( ) . makeHtml ( `## ${ name } (${ date } )\n${ text } ` ) . replace ( / \r ? \n / g, '' ) ;
72+ // Cache results
73+ if ( cache ) changelog [ key ] = parsedHTML ;
74+ return parsedHTML ;
8375}
8476
8577export function load ( version = 'latest' , short = false ) {
0 commit comments