Skip to content

Commit

Permalink
fix link to index page for custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
patwalls committed Jan 3, 2019
1 parent 2405a6f commit e478405
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ def customized_emoji(user)
user.favicon.present? ? user.favicon : "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/155/writing-hand_270d.png"
end

def post_pathy(post)
custom_domain? ? "/#{post.slug}" : "/#{post.user.username}/#{post.slug}"
end

def editable?(user)
current_user && current_user == user
end

def custom_domain?
request.host.present? && request.host != "localhost" && request.host != "youdontneedwp.com" && request.host != "www.youdontneedwp.com"
end

def set_home_meta_tags
set_meta_tags(
title: "You Don't Need WordPress: Create A Blog With Google Docs",
Expand Down
6 changes: 4 additions & 2 deletions app/views/i/posts/_bio.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- home = custom_domain? ? "/" : "/#{user.username}"

.index-bio
.index-bio__left
= link_to "/#{user.username}" do
= link_to home do
- if user.avatar.present?
= image_tag(user.avatar.url)
- else
Expand All @@ -12,7 +14,7 @@
= fa_icon "twitter"
.index-bio__right
.name
= link_to user.name, "/#{user.username}"
= link_to user.name, home
.bio= user.bio
- if editable?(user)
.edit= link_to("edit bio", profile_path)
2 changes: 1 addition & 1 deletion app/views/i/posts/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
= post.published&.strftime("%B #{post.published&.day&.ordinalize}, %Y")
- if post.meta.exists?
.post-meta{ style: "background-image: url(#{post.meta.url})"}
= link_to(post.title, "/#{@user.username}/#{post.slug}")
= link_to(post.title, post_pathy(post))
- if editable?(@user)
.post-bottom
= link_to "Edit Post", edit_post_path(post.id)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190103102215_custom_domain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CustomDomain < ActiveRecord::Migration[5.2]
def change
add_column :users, :custom_domain, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_12_24_051544) do
ActiveRecord::Schema.define(version: 2019_01_03_102215) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -64,6 +64,7 @@
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.string "custom_domain"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down

0 comments on commit e478405

Please sign in to comment.