folder script
This commit is contained in:
		
							parent
							
								
									81bbb7b1d7
								
							
						
					
					
						commit
						37da020523
					
				
					 297 changed files with 3295 additions and 0 deletions
				
			
		
							
								
								
									
										41
									
								
								scripts/add_update_frontmatter.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										41
									
								
								scripts/add_update_frontmatter.sh
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Directory to search for markdown files (content folder)
 | 
			
		||||
search_dir="../content"
 | 
			
		||||
 | 
			
		||||
# Function to check and update frontmatter with the latest date
 | 
			
		||||
update_frontmatter() {
 | 
			
		||||
  local file="$1"
 | 
			
		||||
 | 
			
		||||
  # Check if the file contains frontmatter with +++ delimiters
 | 
			
		||||
  if grep -qE '^\+\+\+' "$file"; then
 | 
			
		||||
    # Extract frontmatter from the file (between +++ markers)
 | 
			
		||||
    frontmatter=$(sed -n '/^\+\+\+/,/^\+\+\+/p' "$file")
 | 
			
		||||
 | 
			
		||||
    # Check if there's a 'date' field in the frontmatter
 | 
			
		||||
    if echo "$frontmatter" | grep -qE 'date\s*='; then
 | 
			
		||||
      # Check if there's already an 'updated' field in the frontmatter
 | 
			
		||||
      if echo "$frontmatter" | grep -qE 'updated\s*='; then
 | 
			
		||||
        echo "✘ Skipped: 'updated' field already present in $file"
 | 
			
		||||
        return
 | 
			
		||||
      fi
 | 
			
		||||
 | 
			
		||||
      # Get the current modification time of the file (formatted as YYYY-MM-DD)
 | 
			
		||||
      last_modified=$(date -r "$file" "+%Y-%m-%d")
 | 
			
		||||
 | 
			
		||||
      # Update the frontmatter by adding the updated date below the 'date = ' line
 | 
			
		||||
      sed -i "/^\+\+\+/ {n;s/$/\nupdated = $last_modified/}" "$file"
 | 
			
		||||
 | 
			
		||||
      echo "✔ Updated frontmatter in $file"
 | 
			
		||||
    else
 | 
			
		||||
      echo "✘ No date field found in the frontmatter of $file"
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    echo "✘ No frontmatter found in $file"
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Recursively find all markdown files in the content folder and apply the update
 | 
			
		||||
find "$search_dir" -type f -name "*.md" | while read file; do
 | 
			
		||||
  update_frontmatter "$file"
 | 
			
		||||
done
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue