Commit 656c7f28 authored by Bat's avatar Bat
Browse files

Personal blog + basic editor

parent 922a4179
......@@ -47,6 +47,7 @@ Amber::Server.configure do |app|
get "/blog", ActivityPub::BlogController, :show
get "/~:name", BlogController, :show
get "/~:name/new", BlogController, :new_post
get "/blogs/new", BlogController, :new
post "/blogs", BlogController, :create
end
......
-- +micrate Up
ALTER TABLE blogs ADD COLUMN account_id BIGINT;
-- +micrate Down
ALTER TABLE blogs DROP COLUMN account_id;
......@@ -20,6 +20,14 @@ class AccountController < ApplicationController
acct.display_name = params["username"]
acct.bio = ""
Repo.insert(acct)
blog = Blog.new
blog.title = params["username"].to_s + "'s blog'"
blog.actor_id = make_actor_id(blog.title.to_s)
blog.subtitle = ""
blog.description = ""
blog.default_license = ""
redirect_to(controller: :account, action: :show, params: {
"name" => acct.actor_id.not_nil!
})
......
class BlogController < ApplicationController
include ActivityPub::Utils
def get_blog
Blog.from_name(params["name"])
end
def show
blog = Blog.from_name(make_actor_id(params["name"]))
blog = get_blog
title = blog.title
render("index.ecr")
end
......@@ -16,11 +20,15 @@ class BlogController < ApplicationController
blog = Blog.new
blog.title = params["title"]
blog.actor_id = make_actor_id(params["title"])
blog.title = params["title"]
blog.subtitle = params["subtitle"]
blog.description = params["description"]
blog.default_license = params["license"]
Repo.insert(blog)
redirect_to(controller: :blog, action: :show, status: 302, params: { "name" => blog.title.not_nil! })
redirect_to(controller: :blog, action: :show, status: 302, params: { "name" => blog.actor_id.not_nil! })
end
def new_post
title = "New Post in " + get_blog.title.not_nil!
render("new_post.ecr")
end
end
......@@ -11,6 +11,7 @@ class Account < Crecto::Model
field :hashed_password, String
field :display_name, String
field :bio, String
has_one :personal_blog, Blog
has_many :posts, Post, dependent: :destroy
belongs_to :instance, Instance
end
......
......@@ -6,6 +6,7 @@ class Blog < Crecto::Model
field :description, String
field :default_license, String
belongs_to :instance, Instance
belongs_to :account, Account
end
def self.from_name (name : String)
......
<main>
<h1 contenteditable>My post</h1>
<div contenteditable>
</div>
</main>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment