Skip to content

Commit

Permalink
ci: fikse feil datoar
Browse files Browse the repository at this point in the history
  • Loading branch information
adalinesimonian committed Feb 24, 2024
1 parent cb3cec7 commit 2d3b770
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/notify.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Notify subscribers of new posts

on:
push:
branches: [main]
workflow_run:
workflows: ['Build and Deploy']
types:
- completed

workflow_dispatch:

Expand All @@ -22,6 +24,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand Down
44 changes: 11 additions & 33 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require 'json'
require 'yaml'
require 'net/http'
require 'optparse'
require 'tzinfo'

def slugify(title)
slug = title.downcase
Expand All @@ -15,6 +16,9 @@ def slugify(title)
slug
end

configuredTimezone = YAML.load_file('_config.yml')['timezone']
timezone = TZInfo::Timezone.get(configuredTimezone)

task :default => [:install, :serve, :build]

desc 'Install dependencies using Bundler'
Expand Down Expand Up @@ -87,7 +91,7 @@ task :notify_new_post do

# safety check so we don't send accidentally notify about old posts
# if the latest post is not from within the last 24 hours, don't notify
if DateTime.parse(new_post['date']).to_time < Time.now - 24 * 60 * 60
if DateTime.parse(new_post['date']).to_time.utc < Time.now.utc - 24 * 60 * 60
puts 'Latest post is older than 24 hours, not notifying'
exit 0
end
Expand Down Expand Up @@ -144,37 +148,6 @@ task :build do
sh 'bundle exec jekyll build'
end

desc 'Create a new post'
task :new_post, [:title] do |t, args|
title = args[:title]

if title.nil?
puts 'Usage: rake new_post[title]'
exit 1
end

now = DateTime.now
date = now.strftime('%Y-%m-%d')
filename = "_posts/#{date}-#{title.downcase.strip.gsub(' ', '-')}.md"
if File.exist?(filename)
puts 'File already exists'
exit 1
end

File.open(filename, 'w') do |file|
file.write("---\n")
file.write("layout: post\n")
file.write("title: \"#{title}\"\n")
file.write("date: #{now.strftime('%Y-%m-%d %H:%M:%S %z')}\n")
file.write("author: \n")
file.write("categories: \n")
file.write("summary: \"\"\n")
file.write("---\n")
end

puts "Created new post: #{filename}"
end

namespace :draft do |args|
desc 'Create a new draft'
task :new do
Expand Down Expand Up @@ -208,6 +181,7 @@ namespace :draft do |args|
file.write("title: \"#{title}\"\n")
file.write("date: #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}\n")
file.write("author: \n")
file.write("image: \n")
file.write("categories: \n")
file.write("summary: \"\"\n")
file.write("---\n")
Expand Down Expand Up @@ -246,7 +220,11 @@ namespace :draft do |args|
end

now = DateTime.now
date = now.strftime('%Y-%m-%d')

utcDate = now.new_offset(0)
localDate = timezone.utc_to_local(utcDate)
date = localDate.strftime('%Y-%m-%d')

filename = "_posts/#{date}-#{slug}.md"
if File.exist?(filename)
puts "Post already exists: #{filename}"
Expand Down
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ url: 'https://blog.ordbokapi.org' # the base hostname & protocol for your site,
bluesky_username: ordbokapi.org
github_username: ordbokapi

timezone: Europe/Oslo

# Build settings
plugins:
- jekyll-feed
Expand Down
7 changes: 5 additions & 2 deletions _plugins/generate_new_post_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def generate(site)
end

# Check for new files in the last commit in the _posts directory
changed_files = `git diff-tree --no-commit-id --name-status -r HEAD`.lines
new_posts = changed_files.select { |line| line.start_with?('A') && line.include?('_posts/') }
changed_files = `git diff-tree --no-commit-id --name-status -r HEAD`
puts changed_files
new_posts = changed_files.lines.select { |line| line.start_with?('A') && line.include?('_posts/') }

if new_posts.empty?
puts 'No new post was created'
Expand Down Expand Up @@ -55,6 +56,8 @@ def generate(site)
File.open(write_path, 'w') do |file|
file.write(JSON.pretty_generate(new_post))
end

puts 'New post JSON written to ' + write_path
end
end
end

0 comments on commit 2d3b770

Please sign in to comment.