web frontend for git (tangled's grandpa)
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

routes: render markdown readmes in repo index (#11)

authored by

James Mills and committed by
GitHub
95dec0f0 0547b042

+30 -6
+4
go.mod
··· 8 8 github.com/dustin/go-humanize v1.0.0 9 9 github.com/go-git/go-billy/v5 v5.3.1 10 10 github.com/go-git/go-git/v5 v5.5.1 11 + github.com/microcosm-cc/bluemonday v1.0.21 12 + github.com/russross/blackfriday/v2 v2.1.0 11 13 golang.org/x/sys v0.3.0 12 14 gopkg.in/yaml.v3 v3.0.0 13 15 ) ··· 16 18 github.com/Microsoft/go-winio v0.6.0 // indirect 17 19 github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect 18 20 github.com/acomagu/bufpipe v1.0.3 // indirect 21 + github.com/aymerick/douceur v0.2.0 // indirect 19 22 github.com/cloudflare/circl v1.3.0 // indirect 20 23 github.com/emirpasic/gods v1.18.1 // indirect 21 24 github.com/go-git/gcfg v1.5.0 // indirect 25 + github.com/gorilla/css v1.0.0 // indirect 22 26 github.com/imdario/mergo v0.3.13 // indirect 23 27 github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 24 28 github.com/kevinburke/ssh_config v1.2.0 // indirect
+8
go.sum
··· 11 11 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= 12 12 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= 13 13 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= 14 + github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= 15 + github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= 14 16 github.com/bluekeyes/go-gitdiff v0.7.0 h1:w4SrRFcufU0/tEpWx3VurDBAnWfpxsmwS7yWr14meQk= 15 17 github.com/bluekeyes/go-gitdiff v0.7.0/go.mod h1:QpfYYO1E0fTVHVZAZKiRjtSGY9823iCdvGXBcEzHGbM= 16 18 github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= ··· 37 39 github.com/go-git/go-git/v5 v5.5.1/go.mod h1:uz5PQ3d0gz7mSgzZhSJToM6ALPaKCdSnl58/Xb5hzr8= 38 40 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 39 41 github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 42 + github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= 43 + github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= 40 44 github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= 41 45 github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= 42 46 github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= ··· 53 57 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 54 58 github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= 55 59 github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= 60 + github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= 61 + github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= 56 62 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 57 63 github.com/pjbgf/sha1cd v0.2.3 h1:uKQP/7QOzNtKYH7UTohZLcjF5/55EnTw0jO/Ru4jZwI= 58 64 github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M= ··· 60 66 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 61 67 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 62 68 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 69 + github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 70 + github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 63 71 github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= 64 72 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= 65 73 github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
+17 -3
routes/routes.go
··· 1 1 package routes 2 2 3 3 import ( 4 + "fmt" 4 5 "html/template" 5 6 "log" 6 7 "net/http" ··· 13 14 "git.icyphox.sh/legit/git" 14 15 "github.com/alexedwards/flow" 15 16 "github.com/dustin/go-humanize" 17 + "github.com/microcosm-cc/bluemonday" 18 + "github.com/russross/blackfriday/v2" 16 19 ) 17 20 18 21 type deps struct { ··· 101 104 return 102 105 } 103 106 104 - var readmeContent string 107 + var readmeContent template.HTML 105 108 for _, readme := range d.c.Repo.Readme { 106 - readmeContent, _ = gr.FileContent(readme) 107 - if readmeContent != "" { 109 + ext := filepath.Ext(readme) 110 + content, _ := gr.FileContent(readme) 111 + if len(content) > 0 { 112 + switch ext { 113 + case ".md": 114 + unsafe := blackfriday.Run([]byte(content), blackfriday.WithExtensions(blackfriday.CommonExtensions)) 115 + html := bluemonday.UGCPolicy().SanitizeBytes(unsafe) 116 + readmeContent = template.HTML(html) 117 + default: 118 + readmeContent = template.HTML( 119 + fmt.Sprintf(`<pre>%s</pre>`, content), 120 + ) 121 + } 108 122 break 109 123 } 110 124 }
+1 -3
templates/repo.html
··· 27 27 </div> 28 28 {{- if .readme }} 29 29 <article class="readme"> 30 - <pre> 31 - {{- .readme -}} 32 - </pre> 30 + {{- .readme -}} 33 31 </article> 34 32 {{- end -}} 35 33