feat: add subpaths
4d628327
3 file(s) · +10 −6
| 82 | 82 | seen := make(map[string]struct{}, n) |
|
| 83 | 83 | links := make([]string, 0, n) |
|
| 84 | 84 | for len(links) < n { |
|
| 85 | - | word := m.words[rand.Intn(len(m.words))] |
|
| 86 | - | if _, dup := seen[word]; dup { |
|
| 85 | + | pair := m.words[rand.Intn(len(m.words))] + "/" + m.words[rand.Intn(len(m.words))] |
|
| 86 | + | if _, dup := seen[pair]; dup { |
|
| 87 | 87 | continue |
|
| 88 | 88 | } |
|
| 89 | - | seen[word] = struct{}{} |
|
| 90 | - | links = append(links, word) |
|
| 89 | + | seen[pair] = struct{}{} |
|
| 90 | + | links = append(links, pair) |
|
| 91 | 91 | } |
|
| 92 | 92 | return links |
|
| 93 | 93 | } |
| 18 | 18 | func main() { |
|
| 19 | 19 | http.HandleFunc("/", IndexHandler) |
|
| 20 | 20 | http.HandleFunc("/{slug}", IndexHandler) |
|
| 21 | + | http.HandleFunc("/{slug}/{slug2}", IndexHandler) |
|
| 21 | 22 | http.HandleFunc("/robots.txt", RobotsHandler) |
|
| 22 | 23 | ||
| 23 | 24 | port := fmt.Sprintf("%s:%s", hostEnv, portEnv) |
| 77 | 77 | func IndexHandler(writer http.ResponseWriter, req *http.Request) { |
|
| 78 | 78 | babbler := sharedBabbler() |
|
| 79 | 79 | var title string |
|
| 80 | - | if req.PathValue("slug") != "" { |
|
| 80 | + | switch { |
|
| 81 | + | case req.PathValue("slug2") != "": |
|
| 82 | + | title = req.PathValue("slug") + " " + req.PathValue("slug2") |
|
| 83 | + | case req.PathValue("slug") != "": |
|
| 81 | 84 | title = req.PathValue("slug") |
|
| 82 | - | } else { |
|
| 85 | + | default: |
|
| 83 | 86 | title = babbler.Generate(2) |
|
| 84 | 87 | } |
|
| 85 | 88 | content := babbler.Generate(500) |