@@ -9,7 +9,7 @@ import RevealZoom from "reveal-zoom";
99import RevealApexchart from "reveal-apexchart" ;
1010import RevealECharts from "reveal-echarts" ;
1111import RevealMermaid from "reveal-mermaid" ;
12- import RevealChartjs from "reveal-chartjs" ;
12+ // import RevealChartjs from "reveal-chartjs";
1313// INFO: non-esm therefore they can't be properly imported:
1414// import * as PdfExport from "reveal-pdfexport";
1515// import * as RevealChalkboard from "reveal-chalkboard";
@@ -18,7 +18,7 @@ import SlidesDown from "slidesdown";
1818
1919// computeURL builds a URL to a raw markdown file from a short human-typable
2020// string, e.g. it turns github.com/slidesdown/slidesdown into
21- // https://raw.githubusercontent.com/jceb /slidesdown/main/SLIDES.md
21+ // https://raw.githubusercontent.com/slidsedown /slidesdown/main/SLIDES.md
2222function computeURL ( defaults , url ) {
2323 if ( ! ( defaults . branch && defaults . resource ) ) {
2424 console . error ( "Default branch and/or resource unset" ) ;
@@ -27,25 +27,36 @@ function computeURL(defaults, url) {
2727 const decodedURL = decodeURI ( url ) ;
2828 let match = "" ;
2929 const githubRegExp = new RegExp (
30- / ^ (?: h t t p s : \/ \/ ) ? g i t h u b \. c o m \/ (?< owner > [ a - z A - Z 0 - 9 _ - ] * ) \/ (?< repo > [ a - z A - Z 0 - 9 _ - ] * ) (?: \/ (?: ( (?< blob > b l o b ) | (?< tree > t r e e ) ) \/ ) ? (?: (?< dir_or_branch > [ ^ / ] * ) \/ ) ? (?< resource > .* ) ) ? / ,
30+ / ^ (?: h t t p s : \/ \/ ) ? g i t h u b \. c o m \/ (?< owner > [ a - z A - Z 0 - 9 _ - ] + ) \/ (?< repo > [ a - z A - Z 0 - 9 _ - ] + ) (?: (?: \/ ( (?< blob > b l o b ) | (?< tree > t r e e ) ) ) ? (?: \/ (?< dir_or_branch > [ ^ / ] + ? ) ) ? (?: \/ (? <resource > .* ) ) ) ? $ / ,
3131 ) ;
3232 // resource is not considered for gists, because there's no safe way to
3333 // determine the resource's name from the provided anchor tag
3434 const gistRegExp = new RegExp (
35- / ^ (?: h t t p s : \/ \/ ) ? g i s t .g i t h u b \. c o m \/ (?< owner > [ a - z A - Z 0 - 9 _ - ] * ) \/ (?< repo > [ a - z A - Z 0 - 9 _ - ] * ) \/ ? / ,
35+ / ^ (?: h t t p s : \/ \/ ) ? g i s t \ .g i t h u b \. c o m \/ (?< owner > [ a - z A - Z 0 - 9 _ - ] + ) \/ (?< repo > [ a - z A - Z 0 - 9 _ - ] + ) \/ ? / ,
3636 ) ;
3737 // gistRegExp.exec("gist.github.com/jceb/4bfcfdcddd2020e5b7e521b9e1044f3b")
3838 // gistRegExp.exec("https://gist.github.com/jceb/4bfcfdcddd2020e5b7e521b9e1044f3b")
3939 // gistRegExp.exec("https://gist.github.com/jceb/4bfcfdcddd2020e5b7e521b9e1044f3b#file-230911_dif_wg_id_presentation-md")
4040 // gistRegExp.exec("https://gist.github.com/jceb/4bfcfdcddd2020e5b7e521b9e1044f3b/#file-230911_dif_wg_id_presentation-md")
4141 // gistRegExp.exec("https://gist.githubusercontent.com/jceb/4bfcfdcddd2020e5b7e521b9e1044f3b/raw/dd6e852ccb04c1690a7e96eb77008240e0fbf69f/SLIDES.md")
42+ const srhtRegExp = new RegExp (
43+ / ^ (?: h t t p s : \/ \/ ) ? ( g i t \. ) ? s r \. h t \/ (?< owner > ~ [ a - z A - Z 0 - 9 _ - ] + ) \/ (?< repo > [ a - z A - Z 0 - 9 _ - ] + ) (?: (?: \/ ( (?< blob > b l o b ) | (?< tree > t r e e ) ) ) ? (?: \/ (?< dir_or_branch > [ ^ / ] + ?) ) ? (?: \/ ( i t e m \/ ) ? (?< resource > .* ) ) ) ? $ / ,
44+ ) ;
45+ // srhtRegExp.exec("https://git.sr.ht/~jceb/test")
46+ // srhtRegExp.exec("https://git.sr.ht/~jceb/test/SLIDES.md")
47+ // srhtRegExp.exec("https://git.sr.ht/~jceb/test/tree")
48+ // srhtRegExp.exec("https://git.sr.ht/~jceb/test/tree/SLIDES.md")
49+ // srhtRegExp.exec("https://git.sr.ht/~jceb/test/tree/main/item/SLIDES.md")
50+ // srhtRegExp.exec("sr.ht/~jceb/test/tree/main/item/SLIDES.md")
51+ // srhtRegExp.exec("sr.ht/~jceb/test/SLIDES.md")
4252 if ( ( match = githubRegExp . exec ( decodedURL ) ) !== null ) {
4353 let resource = `${ defaults . branch } /${ defaults . resource } ` ;
4454 // if tree is present, then the default resouce name must be appended
4555 if ( ( match . groups . blob | match . groups . tree ) && match . groups . dir_or_branch ) {
4656 // if tree or blob are present, then dir_or_branch is the branch - perfect, I can build the URL with confidence
47- resource =
48- `${ match . groups . dir_or_branch } /${ match . groups . resource } /${ defaults . resource } ` ;
57+ resource = `${ match . groups . dir_or_branch } /${
58+ match . groups . resource ? match . groups . resource : defaults . resource
59+ } `;
4960 } else if ( match . groups . blob && match . groups . dir_or_branch ) {
5061 // if tree or blob are not present, then dir_or_branch must be a dir but the branch name can't be determined
5162 resource = `${ match . groups . dir_or_branch } /${
@@ -65,6 +76,32 @@ function computeURL(defaults, url) {
6576 return `https://raw.githubusercontent.com/${ match . groups . owner } /${ match . groups . repo } /${ resource } ` ;
6677 } else if ( ( match = gistRegExp . exec ( decodedURL ) ) !== null ) {
6778 return `https://gist.githubusercontent.com/${ match . groups . owner } /${ match . groups . repo } /raw/SLIDES.md` ;
79+ } else if ( ( match = srhtRegExp . exec ( decodedURL ) ) !== null ) {
80+ // INFO: support for sr.ht is currently broken due to missing CORS headers on sr.ht's side
81+ let resource = `${ defaults . branch } /${ defaults . resource } ` ;
82+ // if tree is present, then the default resouce name must be appended
83+ if ( ( match . groups . blob | match . groups . tree ) && match . groups . dir_or_branch ) {
84+ // if tree or blob are present, then dir_or_branch is the branch - perfect, I can build the URL with confidence
85+ resource = `${ match . groups . dir_or_branch } /${
86+ match . groups . resource ? match . groups . resource : defaults . resource
87+ } `;
88+ } else if ( match . groups . blob && match . groups . dir_or_branch ) {
89+ // if tree or blob are not present, then dir_or_branch must be a dir but the branch name can't be determined
90+ resource = `${ match . groups . dir_or_branch } /${
91+ match . groups . resource ? match . groups . resource : defaults . resource
92+ } `;
93+ } else {
94+ if ( match . groups . dir_or_branch ) {
95+ resource = `${ defaults . branch } /${ match . groups . dir_or_branch } /${
96+ match . groups . resource ? match . groups . resource : defaults . resource
97+ } `;
98+ } else {
99+ resource = `${ defaults . branch } /${
100+ match . groups . resource ? match . groups . resource : defaults . resource
101+ } `;
102+ }
103+ }
104+ return `https://git.sr.ht/${ match . groups . owner } /${ match . groups . repo } /blob/${ resource } ` ;
68105 }
69106 return decodedURL ;
70107}
@@ -192,7 +229,7 @@ async function main(defaults) {
192229 RevealCustomControls ,
193230 // Source: https://github.com/rajgoel/reveal.js-plugins/tree/master/anything
194231 // RevealAnything,
195- RevealChartjs ,
232+ // RevealChartjs,
196233 RevealApexchart ,
197234 RevealECharts ,
198235 RevealMermaid ,
0 commit comments