File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -343,12 +343,25 @@ func prepareHomeTreeSideBarSwitch(ctx *context.Context) {
343343	ctx .Data ["UserSettingCodeViewShowFileTree" ] =  showFileTree 
344344}
345345
346+ func  redirectSrcToRaw (ctx  * context.Context ) bool  {
347+ 	// GitHub redirects a tree path with "?raw=1" to the raw path 
348+ 	// It is useful to embed some raw contents into markdown files, 
349+ 	// then viewing the markdown in "src" path could embed the raw content correctly. 
350+ 	if  ctx .Repo .TreePath  !=  ""  &&  ctx .FormBool ("raw" ) {
351+ 		ctx .Redirect (ctx .Repo .RepoLink  +  "/raw/"  +  ctx .Repo .RefTypeNameSubURL () +  "/"  +  util .PathEscapeSegments (ctx .Repo .TreePath ))
352+ 		return  true 
353+ 	}
354+ 	return  false 
355+ }
356+ 
346357// Home render repository home page 
347358func  Home (ctx  * context.Context ) {
348359	if  handleRepoHomeFeed (ctx ) {
349360		return 
350361	}
351- 
362+ 	if  redirectSrcToRaw (ctx ) {
363+ 		return 
364+ 	}
352365	// Check whether the repo is viewable: not in migration, and the code unit should be enabled 
353366	// Ideally the "feed" logic should be after this, but old code did so, so keep it as-is. 
354367	checkHomeCodeViewable (ctx )
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ func TestRedirectsNoLogin(t *testing.T) {
5454		{"/user2/repo1/src/master" , "/user2/repo1/src/branch/master" },
5555		{"/user2/repo1/src/master/a%2fb.txt" , "/user2/repo1/src/branch/master/a%2fb.txt" },
5656		{"/user2/repo1/src/master/directory/file.txt?a=1" , "/user2/repo1/src/branch/master/directory/file.txt?a=1" },
57+ 		{"/user2/repo1/src/branch/master/directory/file.txt?raw=1&other=2" , "/user2/repo1/raw/branch/master/directory/file.txt" },
5758		{"/user2/repo1/tree/a%2fb?a=1" , "/user2/repo1/src/a%2fb?a=1" },
5859		{"/user2/repo1/blob/123456/%20?a=1" , "/user2/repo1/src/commit/123456/%20?a=1" },
5960		{"/user/avatar/GhosT/-1" , "/assets/img/avatar_default.png" },
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments