Skip to content

Commit

Permalink
Merge pull request #65 from adnjoo/blog
Browse files Browse the repository at this point in the history
blog
  • Loading branch information
adnjoo authored Oct 22, 2024
2 parents 8ab0737 + f650ec6 commit f9f0ff1
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ gem "devise", "~> 4.9"
gem "stripe", "~> 13.0"

gem "mailgun-ruby", "~> 1.2"

gem "redcarpet", "~> 3.6"

gem "front_matter_parser", "~> 1.0"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ GEM
domain_name (0.6.20240107)
drb (2.2.1)
erubi (1.13.0)
front_matter_parser (1.0.1)
globalid (1.2.1)
activesupport (>= 6.1)
http-accept (1.7.0)
Expand Down Expand Up @@ -224,6 +225,7 @@ GEM
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
redcarpet (3.6.0)
regexp_parser (2.9.2)
reline (0.5.10)
io-console (~> 0.5)
Expand Down Expand Up @@ -332,12 +334,14 @@ DEPENDENCIES
capybara
debug
devise (~> 4.9)
front_matter_parser (~> 1.0)
importmap-rails
jbuilder
mailgun-ruby (~> 1.2)
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.2.1, >= 7.2.1.1)
redcarpet (~> 3.6)
rubocop-rails-omakase
selenium-webdriver
sprockets-rails
Expand Down
48 changes: 48 additions & 0 deletions app/controllers/blog_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# app/controllers/blog_controller.rb
class BlogController < ApplicationController
require "redcarpet"
require "front_matter_parser"

def index
markdown_files = available_posts

@posts = markdown_files.map do |file|
parsed = parse_markdown_file(file)

{
title: parsed.front_matter["title"],
slug: File.basename(file, ".md"),
summary: parsed.front_matter["summary"] || parsed.content[0..200],
date: parsed.front_matter["date"]&.to_s
}
end
end

def show
slug = sanitize_slug(params[:slug])
file_path = available_posts.find { |file| File.basename(file, ".md") == slug }

if file_path.present?
parsed = parse_markdown_file(file_path)

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
@post = markdown.render(parsed.content)
else
redirect_to blog_path, alert: "Post not found."
end
end

private

def parse_markdown_file(file)
FrontMatterParser::Parser.parse_file(file)
end

def sanitize_slug(slug)
slug.gsub(/[^0-9a-z\-_]/i, "")
end

def available_posts
Dir.glob(Rails.root.join("app", "views", "posts", "*.md"))
end
end
23 changes: 23 additions & 0 deletions app/views/blog/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="max-w-4xl mx-auto py-12">
<h1 class="text-5xl font-extrabold mb-12 text-center tracking-widest text-black border-b-4 border-black">
Blog
</h1>

<div class="space-y-8">
<% @posts.each do |post| %>
<div class="p-6 bg-gray-100 border-4 border-black shadow-none hover:shadow-xl hover:translate-x-1 hover:translate-y-1 transition-all duration-300">
<h2 class="text-3xl font-bold text-black">
<%= link_to post[:title], blog_post_path(post[:slug]), class: "hover:underline" %>
</h2>

<p class="text-lg font-mono text-gray-800 mt-4 leading-relaxed">
<%= post[:date] || "No date available." %>
</p>

<p class="text-md font-mono text-gray-600 mt-2">
<%= post[:summary] || "No summary available." %>
</p>
</div>
<% end %>
</div>
</div>
15 changes: 15 additions & 0 deletions app/views/blog/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="my-container">
<article class="p-2 shadow-none">
<p class="text-sm font-mono text-gray-600 mb-6">
<%= @post_date %>
</p>

<div class="prose">
<%= @post.html_safe %>
</div>
</article>

<div class="mt-12">
<%= link_to 'Back to blog', blog_path, class: "text-black font-bold underline hover:no-underline transition-all duration-300" %>
</div>
</div>
13 changes: 4 additions & 9 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
<div class="max-w-6xl flex justify-between w-full mx-auto items-center">
<p class="text-xl font-bold">&copy; 2024 <%= APP_NAME %>. All rights reserved.</p>
<div class="flex space-x-4 items-center">
<a href="<%= blog_path %>" class="text-white hover:underline font-bold text-xl">Blog</a>
<a href="<%= pricing_path %>" class="text-white hover:underline font-bold text-xl">Pricing</a>
<a href="<%= GITHUB_LINK %>" target="_blank" class="text-white hover:underline font-bold text-xl flex items-center space-x-2">
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.19 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z"/>
</svg>
<span class="sr-only">GitHub</span>
Open
</a>
<a href="<%= X_LINK %>" target="_blank" class="">
<svg class="w-6 h-6" viewBox="0 0 1200 1227" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M714.163 519.284L1160.89 0H1055.03L667.137 450.887L357.328 0H0L468.492 681.821L0 1226.37H105.866L515.491 750.218L842.672 1226.37H1200L714.137 519.284H714.163ZM569.165 687.828L521.697 619.934L144.011 79.6944H306.615L611.412 515.685L658.88 583.579L1055.08 1150.3H892.476L569.165 687.854V687.828Z" fill="white"/>
</svg>
<span class="sr-only">X</span>
<a href="<%= X_LINK %>" target="_blank" class="text-white hover:underline font-bold text-xl">
X
</a>
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions app/views/posts/introducing-dueltasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

title: "Introducing DuelTasks: Gamify Your Productivity!"
summary: "DuelTasks turns to-do lists into exciting challenges to boost your motivation and accountability!"
date: "2024-10-22"

---

# Introducing DuelTasks: Gamify Your Productivity!

Tired of boring to-do lists? [**DuelTasks**](/) transforms task management with a fun, competitive twist to keep you motivated!

## What is DuelTasks?

DuelTasks is a gamified productivity app where tasks become challenges. Set a deadline, choose a challenger, and stay accountable with real stakes—fail to complete the task, and you pay a penalty!

## Key Features

- **Challenging Tasks**: Turn any task into a duel—win or pay up!
- **Real Rewards**: Set monetary penalties for uncompleted tasks with seamless Stripe integration.
- **Leaderboards**: Track progress, earn rewards, and stay motivated.
- **Multiplayer To-Dos**: Collaborate or challenge others to complete tasks together.

## Why It Works

Gamification taps into your competitive side, making tasks more engaging and harder to ignore. DuelTasks' penalty system adds accountability to keep you on track.

## Get Started

Turn tasks into fun challenges. [Sign up for DuelTasks](/users/sign_in) and start winning today!

---

Stay competitive and get things done with DuelTasks!
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
# Static Pages
get "about", to: "pages#about", as: :about

# Blog
get "/blog", to: "blog#index"
get "/blog/:slug", to: "blog#show", as: "blog_post"

# API namespace for isolated routes
namespace :api do
get "hello", to: proc { [ 200, { "Content-Type" => "application/json" }, [ '{"message":"Hello, World!"}' ] ] }
Expand Down

0 comments on commit f9f0ff1

Please sign in to comment.