mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	commands: Add listExpiredCmd for expired pages
This commit is contained in:
		
				
					committed by
					
						
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							51f7cd9bde
						
					
				
				
					commit
					5461a5e03d
				
			@@ -25,6 +25,7 @@ import (
 | 
			
		||||
func init() {
 | 
			
		||||
	listCmd.AddCommand(listDraftsCmd)
 | 
			
		||||
	listCmd.AddCommand(listFutureCmd)
 | 
			
		||||
	listCmd.AddCommand(listExpiredCmd)
 | 
			
		||||
	listCmd.PersistentFlags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
 | 
			
		||||
	listCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
 | 
			
		||||
}
 | 
			
		||||
@@ -98,3 +99,34 @@ posted in the future.`,
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var listExpiredCmd = &cobra.Command{
 | 
			
		||||
	Use:   "expired",
 | 
			
		||||
	Short: "List all posts already expired",
 | 
			
		||||
	Long: `List all of the posts in your content directory which has already
 | 
			
		||||
expired.`,
 | 
			
		||||
	RunE: func(cmd *cobra.Command, args []string) error {
 | 
			
		||||
 | 
			
		||||
		if err := InitializeConfig(); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		viper.Set("BuildExpired", true)
 | 
			
		||||
 | 
			
		||||
		site := &hugolib.Site{}
 | 
			
		||||
 | 
			
		||||
		if err := site.Process(); err != nil {
 | 
			
		||||
			return newSystemError("Error Processing Source Content", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for _, p := range site.Pages {
 | 
			
		||||
			if p.IsExpired() {
 | 
			
		||||
				fmt.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user