nixos-config

My NixOS configuration files

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
  155. 155
  156. 156
diff --git a/git/git.go b/git/git.go
index d55460f..768966a 100644
--- a/git/git.go
+++ b/git/git.go
@@ -143,13 +143,7 @@ func (g *GitRepo) FileContent(path string) (string, error) {
 		return "", err
 	}
 
-	isbin, _ := file.IsBinary()
-
-	if !isbin {
-		return file.Contents()
-	} else {
-		return "Not displaying binary file", nil
-	}
+	return file.Contents()
 }
 
 func (g *GitRepo) Tags() ([]*TagReference, error) {
diff --git a/go.mod b/go.mod
index 9491e43..bc6a398 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,9 @@
 module github.com/pocka/legit
 
-go 1.22.0
+go 1.25
 
 require (
-	github.com/alecthomas/chroma/v2 v2.14.0
+	github.com/alecthomas/chroma/v2 v2.27.0
 	github.com/bluekeyes/go-gitdiff v0.8.0
 	github.com/cyphar/filepath-securejoin v0.4.1
 	github.com/dustin/go-humanize v1.0.1
@@ -20,7 +20,7 @@ require (
 	github.com/acomagu/bufpipe v1.0.4 // indirect
 	github.com/aymerick/douceur v0.2.0 // indirect
 	github.com/cloudflare/circl v1.6.0 // indirect
-	github.com/dlclark/regexp2 v1.11.4 // indirect
+	github.com/dlclark/regexp2/v2 v2.2.1 // indirect
 	github.com/emirpasic/gods v1.18.1 // indirect
 	github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
 	github.com/go-git/go-billy/v5 v5.6.2 // indirect
diff --git a/go.sum b/go.sum
index f8ba6ba..6a89c93 100644
--- a/go.sum
+++ b/go.sum
@@ -6,12 +6,12 @@ github.com/ProtonMail/go-crypto v1.1.5 h1:eoAQfK2dwL+tFSFpr7TbOaPNUbPiJj4fLYwwGE
 github.com/ProtonMail/go-crypto v1.1.5/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
 github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
 github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
-github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE=
-github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
-github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
-github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I=
-github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
-github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
+github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
+github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
+github.com/alecthomas/chroma/v2 v2.27.0 h1:FodwmyOBgJULFYmDqibcp9pvfDLWdtPRh9v/r5BXYZs=
+github.com/alecthomas/chroma/v2 v2.27.0/go.mod h1:NjJ3ciIgrqBNeIkWZ4e46nseoLDslxU1LmfCoL+wcY8=
+github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
+github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
 github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
@@ -30,8 +30,8 @@ github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGL
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
-github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
+github.com/dlclark/regexp2/v2 v2.2.1 h1:mf4KkFUj0gJuarK8P+LgiS+Lit7m9N1yAwEfPbee7R0=
+github.com/dlclark/regexp2/v2 v2.2.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
 github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
 github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
 github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
diff --git a/routes/routes.go b/routes/routes.go
index 71a0d67..4767e48 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -138,7 +138,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
 						return blackfriday.GoToNext
 					}
 
-					if node.Type == blackfriday.Link {
+					if node.Type == blackfriday.Link || node.Type == blackfriday.Image {
 						href := string(node.LinkData.Destination)
 						parsedURL, err := url.Parse(href)
 						if err == nil && parsedURL.Host != "" {
@@ -151,7 +151,9 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
 							href = "." + href
 						}
 
-						if strings.LastIndexByte(href, '/') == len(href)-1 {
+						if node.Type == blackfriday.Image {
+							node.LinkData.Destination = fmt.Appendf([]byte{}, "/%s/blob/%s/%s?raw=true", name, mainBranch, href)
+						} else if strings.LastIndexByte(href, '/') == len(href)-1 {
 							node.LinkData.Destination = fmt.Appendf([]byte{}, "/%s/tree/%s/%s", name, mainBranch, href)
 							node.LinkData.Destination = node.LinkData.Destination[:len(node.LinkData.Destination)-1]
 						} else {
@@ -188,6 +190,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
 	}
 
 	if readmeContent == "" {
+		readmeContent = template.HTML(fmt.Sprintf("no readme found for %s", name))
 		log.Printf("no readme found for %s", name)
 	}
 
@@ -404,13 +407,11 @@ func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
 		PreviewTypes: previewTypes,
 	}
 
-	if d.c.Meta.SyntaxHighlight {
-		highlighted, err := highlightCode(treePath, contents)
-		if err != nil {
-			log.Println(err)
-		} else {
-			data.SyntaxHighlightedContent = highlighted
-		}
+	highlighted, err := highlightCode(treePath, contents)
+	if err != nil {
+		log.Println(err)
+	} else {
+		data.SyntaxHighlightedContent = highlighted
 	}
 
 	if err := t.ExecuteTemplate(w, "repo-blob-ref", data); err != nil {
diff --git a/templates/repo-blob-ref.html.tmpl b/templates/repo-blob-ref.html.tmpl
index a0876df..7518c2f 100644
--- a/templates/repo-blob-ref.html.tmpl
+++ b/templates/repo-blob-ref.html.tmpl
@@ -73,6 +73,10 @@ SPDX-License-Identifier: MIT
 		<aside class="aside">
 			<dl class="metadata">
 				{{- template "tab-selector" -}}
+				<dt class="metadata--key">Raw</dt>
+				<dd class="metadata--value">
+					<a href="?raw=true">View raw</a>
+				</dd>
 				{{- range .PreviewTypes -}}
 				<dt class="metadata--key">Preview (<span class="preview-type">{{ . }}</span>)</dt>
 				<dd class="metadata--value">
diff --git a/templates/repo-list.html.tmpl b/templates/repo-list.html.tmpl
index efb2c37..9f78372 100644
--- a/templates/repo-list.html.tmpl
+++ b/templates/repo-list.html.tmpl
@@ -18,6 +18,7 @@ SPDX-License-Identifier: MIT
 			<div class="header-title">
 				<h1 class="header-title--name">{{ .Config.Meta.Title }}</h1>
 				<p class="header-title--description">{{ .Config.Meta.Description }}</p>
+				<p class="header-title--description">Powered by <a href="https://git.pocka.jp/legit.git">pocka/legit</a></p>
 			</div>
 		</header>
 		<main class="main">