Skip to content

Commit

Permalink
feat: Implement directory exclusion
Browse files Browse the repository at this point in the history
Adds the ability to exclude directories from being parsed
by the crawler. This is achieved by adding a new
`EXCLUDED` file to the directory that should be ignored.
  • Loading branch information
JasonLovesDoggo committed Jan 16, 2025
1 parent ea71cac commit 87f227f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
27 changes: 11 additions & 16 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ Categorized wallpaper showcase. two pictures per category.

## [abstract](.././abstract)

[![a_close_up_of_a_painting.webp](.././abstract/a_close_up_of_a_painting.webp)](.././abstract/a_close_up_of_a_painting.webp)
[![a_group_of_planets_in_space.webp](.././abstract/a_group_of_planets_in_space.webp)](.././abstract/a_group_of_planets_in_space.webp)

[![a_snow_covered_mountains_with_a_red_and_white_line.webp](.././abstract/a_snow_covered_mountains_with_a_red_and_white_line.webp)](.././abstract/a_snow_covered_mountains_with_a_red_and_white_line.webp)


## [animated](.././animated)

[![unicorn-video4.mp4](.././animated/unicorn-video4.mp4)](.././animated/unicorn-video4.mp4)


## [anime](.././anime)

[![a_woman_in_a_hat_holding_a_lantern.webp](.././anime/a_woman_in_a_hat_holding_a_lantern.webp)](.././anime/a_woman_in_a_hat_holding_a_lantern.webp)
Expand All @@ -28,23 +23,23 @@ Categorized wallpaper showcase. two pictures per category.

## [apocalypse](.././apocalypse)

[![a_car_parked_outside_a_motel.webp](.././apocalypse/a_car_parked_outside_a_motel.webp)](.././apocalypse/a_car_parked_outside_a_motel.webp)
[![a_room_with_a_desk_and_a_chair_and_a_skull_on_the_wall.webp](.././apocalypse/a_room_with_a_desk_and_a_chair_and_a_skull_on_the_wall.webp)](.././apocalypse/a_room_with_a_desk_and_a_chair_and_a_skull_on_the_wall.webp)

[![a_motorcycle_parked_outside_a_restaurant.webp](.././apocalypse/a_motorcycle_parked_outside_a_restaurant.webp)](.././apocalypse/a_motorcycle_parked_outside_a_restaurant.webp)
[![a_power_lines_and_power_poles.webp](.././apocalypse/a_power_lines_and_power_poles.webp)](.././apocalypse/a_power_lines_and_power_poles.webp)


## [arcane](.././arcane)

[![a_woman_standing_in_a_room_with_a_city_in_the_background.webp](.././arcane/a_woman_standing_in_a_room_with_a_city_in_the_background.webp)](.././arcane/a_woman_standing_in_a_room_with_a_city_in_the_background.webp)
[![a_building_with_towers_and_a_blue_sky.webp](.././arcane/a_building_with_towers_and_a_blue_sky.webp)](.././arcane/a_building_with_towers_and_a_blue_sky.webp)

[![a_cartoon_of_a_toy_rabbit_sitting_on_a_machine.webp](.././arcane/a_cartoon_of_a_toy_rabbit_sitting_on_a_machine.webp)](.././arcane/a_cartoon_of_a_toy_rabbit_sitting_on_a_machine.webp)
[![a_man_standing_next_to_a_person.webp](.././arcane/a_man_standing_next_to_a_person.webp)](.././arcane/a_man_standing_next_to_a_person.webp)


## [catppuccin](.././catppuccin)

[![a_black_and_white_fractal.png](.././catppuccin/a_black_and_white_fractal.png)](.././catppuccin/a_black_and_white_fractal.png)
[![a_city_skyline_at_night.webp](.././catppuccin/a_city_skyline_at_night.webp)](.././catppuccin/a_city_skyline_at_night.webp)

[![a_cat_on_a_rainbow_colored_line.webp](.././catppuccin/a_cat_on_a_rainbow_colored_line.webp)](.././catppuccin/a_cat_on_a_rainbow_colored_line.webp)
[![dark-cat.png](.././catppuccin/dark-cat.png)](.././catppuccin/dark-cat.png)


## [cyberpunk](.././cyberpunk)
Expand All @@ -61,7 +56,7 @@ Categorized wallpaper showcase. two pictures per category.

## [minimalistic](.././minimalistic)

[![a_man_standing_in_a_forest.webp](.././minimalistic/a_man_standing_in_a_forest.webp)](.././minimalistic/a_man_standing_in_a_forest.webp)
[![a_cartoon_of_two_white_people.webp](.././minimalistic/a_cartoon_of_two_white_people.webp)](.././minimalistic/a_cartoon_of_two_white_people.webp)

[![a_cat_with_ears_and_eyes.webp](.././minimalistic/a_cat_with_ears_and_eyes.webp)](.././minimalistic/a_cat_with_ears_and_eyes.webp)

Expand All @@ -70,14 +65,14 @@ Categorized wallpaper showcase. two pictures per category.

[![a_tree_with_red_leaves_and_Mount_Fuji_in_the_background.webp](.././nature/a_tree_with_red_leaves_and_Mount_Fuji_in_the_background.webp)](.././nature/a_tree_with_red_leaves_and_Mount_Fuji_in_the_background.webp)

[![a_lake_surrounded_by_trees_and_a_cave.webp](.././nature/a_lake_surrounded_by_trees_and_a_cave.webp)](.././nature/a_lake_surrounded_by_trees_and_a_cave.webp)
[![a_bridge_over_water_with_trees_around_it.webp](.././nature/a_bridge_over_water_with_trees_around_it.webp)](.././nature/a_bridge_over_water_with_trees_around_it.webp)


## [nord](.././nord)

[![a_person_in_a_hoodie.webp](.././nord/a_person_in_a_hoodie.webp)](.././nord/a_person_in_a_hoodie.webp)
[![a_logo_of_a_microsoft_windows.webp](.././nord/a_logo_of_a_microsoft_windows.webp)](.././nord/a_logo_of_a_microsoft_windows.webp)

[![a_graphic_design_of_a_bird.webp](.././nord/a_graphic_design_of_a_bird.webp)](.././nord/a_graphic_design_of_a_bird.webp)
[![a_mountain_with_a_pink_sky.webp](.././nord/a_mountain_with_a_pink_sky.webp)](.././nord/a_mountain_with_a_pink_sky.webp)


## [pixelart](.././pixelart)
Expand Down
22 changes: 18 additions & 4 deletions .github/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (

const (
DescriptionFile = "DESCRIPTION"
ExcludedFile = "EXCLUDED"
MaxFilesPerCategory = 2
)

var (
BaseDir string
IgnoredDirectories = []string{".github", ".idea", ".git"}
IgnoredFiles = []string{".gitignore", OutputFile, DescriptionFile, ".DS_Store", ".gitkeep"}
IgnoredFiles = []string{".gitignore", OutputFile, DescriptionFile, ExcludedFile, ".DS_Store", ".gitkeep"}
ImageExtensions = []string{".jpg", ".jpeg", ".png", ".webp", ".mp4"}
CategoryReadmeTemplate string
RootReadmeTemplate string
Expand Down Expand Up @@ -73,7 +74,7 @@ func getEstimatedCollectionsCount(root string) int {
return count
}

func ParseDirectories(root string) []Collection {
func ParseDirectories(root string, respectIgnore bool) []Collection {
collections := make([]Collection, 0, getEstimatedCollectionsCount(root))
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand All @@ -93,7 +94,16 @@ func ParseDirectories(root string) []Collection {
return nil
}

collection, err := ParseDirectory(path)
// Check for the presence of ExcludedFile
excludedFilePath := filepath.Join(path, ExcludedFile)
fmt.Printf("Checking for excluded file: %s\n", excludedFilePath)
if _, err := os.Stat(excludedFilePath); err == nil {
fmt.Printf("Excluded file found, skipping directory %s\n", path)
// ExcludedFile exists, skip this directory
return filepath.SkipDir
}

collection, err := ParseDirectory(path, respectIgnore)
if err != nil {
fmt.Printf("Error parsing directory %s: %v\n", path, err)
return nil
Expand All @@ -117,7 +127,7 @@ func ParseDirectories(root string) []Collection {
return collections
}

func ParseDirectory(path string) (Collection, error) {
func ParseDirectory(path string, respectIgnore bool) (Collection, error) {
exists, err := os.Stat(path)
if err != nil {
return Collection{}, err
Expand Down Expand Up @@ -149,6 +159,10 @@ func ParseDirectory(path string) (Collection, error) {
fmt.Printf("Error creating category README for %s: %v\n", path, err)
}

if respectIgnore {

}

return Collection{
Name: filepath.Base(path),
Files: getRandomizedFiles(imageFiles, MaxFilesPerCategory),
Expand Down
2 changes: 1 addition & 1 deletion .github/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (

func main() {
// Collect all collections
collections := ParseDirectories("../")
collections := ParseDirectories("../", true)

// Create root README
err := createRootReadme(collections)
Expand Down
Empty file added animated/EXCLUDED
Empty file.

0 comments on commit 87f227f

Please sign in to comment.