Pārlūkot izejas kodu

Indicate directories and executable files

Directories get slash appended and color coding
Other-executable files get color coding
master
Matt Baer pirms 9 gadiem
vecāks
revīzija
b745d5c627
2 mainītis faili ar 32 papildinājumiem un 3 dzēšanām
  1. +17
    -2
      code.go
  2. +15
    -1
      templates/code.html

+ 17
- 2
code.go Parādīt failu

@@ -38,6 +38,7 @@ type User struct {
type Project struct {
Name string
Path string
CssClass string
}

func findProjects() map[string]User {
@@ -72,11 +73,25 @@ func mapFiles(files *[]string, users map[string]User) {
// Ensure file is other-readable
// TODO: just detect if we can actually read this, instead
info, _ := os.Stat(path)
if info.Mode() & 0004 == 0 {
mode := info.Mode()
if mode & 0004 == 0 {
continue
}

proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1)}
// Mark directories vs. regular files
cssClass := "file"
if mode.IsDir() {
path = path + "/"
fname = fname + "/"
cssClass = "dir"
}

// Check if files are executable by all
if mode & 0001 != 0 {
cssClass = cssClass + " exec"
}

proj := &Project{Name: fname, Path: strings.Replace(path, "/home/", "~", -1), CssClass: cssClass}
u, exists := users[uname]
if !exists {
fmt.Printf("Found %s for ~%s.\n", pparts[3], uname)


+ 15
- 1
templates/code.html Parādīt failu

@@ -5,6 +5,20 @@
<title>{{.FolderName}} on {{.Host}}</title>

<link type="text/css" rel="stylesheet" href="tilde.css" />
<style type="text/css">
.dir {
font-weight: bold;
color: #00BFFF;
}
.file.exec {
font-weight: bold;
color: #FFD700;
}
.fullDir {
color: #aaa;
font-size: 0.9em;
}
</style>

</head>
<body id="hello">
@@ -17,7 +31,7 @@
<div class="links">
<ul class="links">
{{range .Projects}}
<li><strong>{{.Name}}</strong> &middot; {{.Path}}</li>
<li><span class="{{.CssClass}}">{{.Name}}</span> <span class="fullDir">&middot; {{.Path}}</span></li>
{{end}}
</ul>
</div>


Notiek ielāde…
Atcelt
Saglabāt