File tree 5 files changed +76
-1
lines changed
5 files changed +76
-1
lines changed Original file line number Diff line number Diff line change 24
24
github_token : ${{ secrets.GITHUB_TOKEN }}
25
25
keep_files : true
26
26
publish_dir : ./book
27
- destination_dir : ./
27
+ destination_dir : ./latest
Original file line number Diff line number Diff line change
1
+ name : Build docs
2
+
3
+ on :
4
+ release :
5
+ types : [published]
6
+
7
+ jobs :
8
+ deploy :
9
+ runs-on : ubuntu-20.04
10
+ steps :
11
+ - uses : actions/checkout@v2
12
+
13
+ - name : Get release tag
14
+ run : echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
15
+
16
+ - name : Setup mdBook
17
+ uses : peaceiris/actions-mdbook@v1
18
+ with :
19
+ mdbook-version : ' 0.4.11'
20
+
21
+ - name : Set version of docs
22
+ run : echo 'window.HOOKSHOT_VERSION = "${{ env.RELEASE_VERSION }}";' > ./docs/_site/version.js
23
+
24
+ - run : mdbook build
25
+
26
+ - name : Deploy latest
27
+ uses : peaceiris/actions-gh-pages@v3
28
+ with :
29
+ github_token : ${{ secrets.GITHUB_TOKEN }}
30
+ keep_files : true
31
+ publish_dir : ./book
32
+ destination_dir : ./${{ env.RELEASE_VERSION }}
Original file line number Diff line number Diff line change @@ -22,3 +22,8 @@ git-repository-url = "https://github.com/matrix-org/matrix-hookshot"
22
22
additional-css = [
23
23
" docs/_site/style.css"
24
24
]
25
+
26
+ additional-js = [
27
+ " docs/_site/main.js" ,
28
+ " docs/_site/version.js"
29
+ ]
Original file line number Diff line number Diff line change
1
+ window . addEventListener ( "load" , ( ) => {
2
+ const scrollbox = document . querySelector ( ".sidebar-scrollbox" ) ;
3
+ scrollbox . innerHTML = `<div class="version-box"><span>Version: </span></div>${ scrollbox . innerHTML } ` ;
4
+ const currentVersion = window . HOOKSHOT_VERSION || 'latest' ;
5
+
6
+ const selectElement = document . createElement ( "select" ) ;
7
+
8
+ fetch ( "https://api.github.com/repos/matrix-org/matrix-hookshot/releases" , {
9
+ cache : "force-cache" ,
10
+ } ) . then ( res =>
11
+ res . json ( )
12
+ ) . then ( releases => {
13
+ selectElement . innerHTML = "" ;
14
+ for ( const version of [ 'latest' , ...releases . map ( r => r . tag_name ) . filter ( s => s !== "0.1.0" ) ] ) {
15
+ const option = document . createElement ( "option" ) ;
16
+ option . innerHTML = version ;
17
+ selectElement . add ( option ) ;
18
+ if ( currentVersion === version ) {
19
+ option . setAttribute ( 'selected' , '' ) ;
20
+ }
21
+ }
22
+ } ) . catch ( ex => {
23
+ console . error ( "Failed to fetch version data" , ex ) ;
24
+ } )
25
+
26
+ const option = document . createElement ( "option" ) ;
27
+ option . innerHTML = 'loading...' ;
28
+ selectElement . add ( option ) ;
29
+
30
+ selectElement . addEventListener ( 'change' , ( event ) => {
31
+ const versionlessPath = window . location . pathname . split ( '/' ) . slice ( 2 ) . join ( '/' ) ;
32
+ window . location = `${ window . location . origin } /${ event . target . value } /${ versionlessPath } ` ;
33
+ } ) ;
34
+
35
+ document . querySelector ( ".version-box" ) . appendChild ( selectElement ) ;
36
+ } ) ;
Original file line number Diff line number Diff line change
1
+ // This is modified by the build script
2
+ window . HOOKSHOT_VERSION = "latest" ;
You can’t perform that action at this time.
0 commit comments