@@ -10,7 +10,11 @@ import { basename, join } from "path/mod.ts";
1010
1111import * as ld from "../../../core/lodash.ts" ;
1212
13- import { safeExistsSync } from "../../../core/path.ts" ;
13+ import {
14+ ensureTrailingSlash ,
15+ pathWithForwardSlashes ,
16+ safeExistsSync ,
17+ } from "../../../core/path.ts" ;
1418import { FormatLanguage , Metadata } from "../../../config/types.ts" ;
1519
1620import {
@@ -44,6 +48,7 @@ import {
4448 kSiteReaderMode ,
4549 kSiteRepoActions ,
4650 kSiteRepoBranch ,
51+ kSiteRepoSubdir ,
4752 kSiteRepoUrl ,
4853 kSiteSidebar ,
4954 kSiteSidebarStyle ,
@@ -118,6 +123,7 @@ export async function bookProjectConfig(
118123 site [ kSiteUrl ] = book [ kSiteUrl ] ;
119124 site [ kSitePath ] = book [ kSitePath ] ;
120125 site [ kSiteRepoUrl ] = book [ kSiteRepoUrl ] ;
126+ site [ kSiteRepoSubdir ] = book [ kSiteRepoSubdir ] ;
121127 site [ kSiteRepoBranch ] = book [ kSiteRepoBranch ] ;
122128 site [ kSiteRepoActions ] = book [ kSiteRepoActions ] ;
123129 site [ kSiteNavbar ] = book [ kSiteNavbar ] ;
@@ -190,7 +196,7 @@ export async function bookProjectConfig(
190196 // code tools
191197 const tools = [ ] ;
192198 if ( site [ kSiteRepoUrl ] ) {
193- const repoUrl = site [ kSiteRepoUrl ] as string ;
199+ const repoUrl = siteRepoUrl ( site ) ;
194200 const icon = repoUrlIcon ( repoUrl ) ;
195201 tools . push ( {
196202 text : "Source Code" ,
@@ -228,6 +234,19 @@ export async function bookProjectConfig(
228234 return websiteProjectConfig ( projectDir , config , forceHtml ) ;
229235}
230236
237+ function siteRepoUrl ( site : Metadata ) {
238+ const repoUrl = site [ kSiteRepoUrl ] as string ;
239+ if ( site [ kSiteRepoSubdir ] ) {
240+ const subdir = ensureTrailingSlash ( site [ kSiteRepoSubdir ] as string ) ;
241+ const branch = site [ kSiteRepoBranch ] || "main" ;
242+ return pathWithForwardSlashes (
243+ join ( repoUrl , `tree/${ branch } /${ subdir } ` ) ,
244+ ) ;
245+ } else {
246+ return repoUrl ;
247+ }
248+ }
249+
231250const variableRegex = / { { <\s * v a r \s + ( .* ?) \s * > } } / gm;
232251function resolveVariables ( value : string , config : ProjectConfig ) {
233252 variableRegex . lastIndex = 0 ;
0 commit comments