Skip to content

Commit

Permalink
post
Browse files Browse the repository at this point in the history
  • Loading branch information
adnjoo committed Oct 22, 2024
1 parent 4697eb0 commit f650ec6
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ gem "stripe", "~> 13.0"
gem "mailgun-ruby", "~> 1.2"

gem "redcarpet", "~> 3.6"

gem "front_matter_parser", "~> 1.0"
2 changes: 2 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 @@ -333,6 +334,7 @@ DEPENDENCIES
capybara
debug
devise (~> 4.9)
front_matter_parser (~> 1.0)
importmap-rails
jbuilder
mailgun-ruby (~> 1.2)
Expand Down
25 changes: 18 additions & 7 deletions app/controllers/blog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# app/controllers/blog_controller.rb
class BlogController < ApplicationController
require "redcarpet"
require "front_matter_parser"

def index
@posts = available_posts.map do |file_path|
markdown_files = available_posts

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

{
title: File.basename(file_path, ".md").titleize,
slug: File.basename(file_path, ".md")
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
Expand All @@ -16,21 +23,25 @@ def show
file_path = available_posts.find { |file| File.basename(file, ".md") == slug }

if file_path.present?
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
@post = markdown.render(File.read(file_path))
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

# Sanitize the slug to allow only valid characters
def parse_markdown_file(file)
FrontMatterParser::Parser.parse_file(file)
end

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

# List all available Markdown files
def available_posts
Dir.glob(Rails.root.join("app", "views", "posts", "*.md"))
end
Expand Down
27 changes: 22 additions & 5 deletions app/views/blog/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<div class="my-container">
<h1>Blog</h1>
<% @posts.each do |post| %>
<h2><%= link_to post[:title], blog_post_path(post[:slug]) %></h2>
<% end %>
<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>
17 changes: 13 additions & 4 deletions app/views/blog/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<div class="my-container">
<article>
<%= @post.html_safe %>
<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>
<%= link_to 'Back to blog', blog_path %>
</div>

<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>
7 changes: 0 additions & 7 deletions app/views/posts/first-post.md

This file was deleted.

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!

0 comments on commit f650ec6

Please sign in to comment.