Skip to content

Commit

Permalink
fix: homepage bio clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Nov 14, 2022
1 parent 205123c commit c366bbb
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 153 deletions.
15 changes: 8 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"plugins": ["react", "prettier"],
"rules": {
"indent": ["error", 4],
"jsx-a11y/label-has-associated-control": ["error", {
"labelAttributes": ["htmlFor"]
}],
"jsx-a11y/label-has-associated-control": [
"error",
{
"labelAttributes": ["htmlFor"]
}
],
"quotes": ["error", "double"],
"react/jsx-indent": [2, 4],
"react/jsx-indent-props": [2, 4],
"react/jsx-props-no-spreading": [0]
}
}
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": false,
"trailingComma": "all",
"printWidth": 120,
"semi": true,
"tabWidth": 4
}
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ AllCops:
- 'config/**/*'
- 'script/**/*'
- 'bin/{rails,rake}'
- !ruby/regexp /old_and_unused\.rb$/
Metrics/MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Layout/LineLength:
Max: 100
Max: 100
Style/ConditionalAssignment:
Enabled: false
12 changes: 10 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ GEM
ffi (1.15.4)
globalid (1.0.0)
activesupport (>= 5.0)
google-protobuf (3.19.1)
google-protobuf (3.19.1-x86_64-darwin)
google-protobuf (3.19.1-x86_64-linux)
googleapis-common-protos-types (1.3.0)
google-protobuf (~> 3.14)
grpc (1.42.0)
google-protobuf (~> 3.18)
googleapis-common-protos-types (~> 1.0)
grpc (1.42.0-x86_64-darwin)
google-protobuf (~> 3.18)
googleapis-common-protos-types (~> 1.0)
Expand All @@ -160,6 +164,7 @@ GEM
i18n (1.8.11)
concurrent-ruby (~> 1.0)
jmespath (1.4.0)
libv8-node (16.10.0.0-arm64-darwin)
libv8-node (16.10.0.0-x86_64-darwin)
libv8-node (16.10.0.0-x86_64-linux)
listen (3.0.8)
Expand All @@ -182,7 +187,7 @@ GEM
libv8-node (~> 16.10.0.0)
minitest (5.14.4)
multipart-post (2.1.1)
mysql2 (0.5.3)
mysql2 (0.5.4)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
Expand All @@ -191,6 +196,8 @@ GEM
newrelic_rpm (= 8.2.0)
newrelic_rpm (8.2.0)
nio4r (2.5.8)
nokogiri (1.12.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-linux)
Expand Down Expand Up @@ -316,6 +323,7 @@ GEM
chronic (>= 0.6.3)

PLATFORMS
arm64-darwin-21
x86_64-darwin-18
x86_64-darwin-20
x86_64-linux
Expand Down Expand Up @@ -364,4 +372,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
2.2.32
2.3.15
2 changes: 1 addition & 1 deletion app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def email_subscribe

def redirect_to_authenticated_usage(author, secret)
@secret_url = CGI.escape("#{author.get_host}/authors/#{author.id}/extension/?secret=#{secret}&type=sn")
redirect_to "#{ENV['HOST']}/new_author?secret_url=#{@secret_url}"
redirect_to "#{ENV['HOST']}/new-author?secret_url=#{@secret_url}"
end

def extension
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/usage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ def index

def new_author
@title = 'New Author | Listed'
if params[:secret_url]
@secret_url = Base64.encode64(params[:secret_url])
else
redirect_to '/'
end
end
end
22 changes: 17 additions & 5 deletions app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Author < ApplicationRecord
update_homepage_status
end

def string_has_restrictions(string, restrictions)
return false if !string || string.empty?
restrictions.any? { |word| string.downcase.include?(word.downcase) }
end

def update_homepage_status(should_save = false)
most_recent_post = listed_posts.where(
'(posts.created_at >= ? AND posts.created_at <= ?)',
Expand All @@ -39,13 +44,20 @@ def update_homepage_status(should_save = false)
!hide_from_homepage &&
has_bio

if featured
self.homepage_activity = DateTime.now
elsif post_criteria
self.homepage_activity = most_recent_post.created_at
else
if featured
self.homepage_activity = DateTime.now
elsif post_criteria
restricted_words = (ENV['RESTRICTED_KEYWORDS'] || '').split(',')
if string_has_restrictions(bio, restricted_words) ||
string_has_restrictions(display_name, restricted_words) ||
string_has_restrictions(personal_link, restricted_words)
self.homepage_activity = nil
else
self.homepage_activity = most_recent_post.created_at
end
else
self.homepage_activity = nil
end

save if homepage_activity_changed? && should_save
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def link_transformer
elements: ['a', 'a img'],
attributes: {'a' => ['href']},
add_attributes: {
'a' => {'rel' => "noopener", 'target' => "_blank"}
'a' => {'rel' => "noopener nofollow", 'target' => "_blank"}
}
}
) unless node_url.host.include? author_url.host
Expand Down
13 changes: 4 additions & 9 deletions client/app/components/authors/header/AuthorInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const AuthorInfo = ({ author }) => {
{author.header_image_url ? (
<div style={{ backgroundImage: `url(${author.header_image_url})` }} className="header-image" />
) : (
<p className="header-author-capital">
{author.title[0]}
</p>
<p className="header-author-capital">{author.title[0]}</p>
)}
</div>
<div>
Expand All @@ -30,20 +28,19 @@ const AuthorInfo = ({ author }) => {
<a
href={`https://twitter.com/${author.twitter}`}
target="_blank"
rel="noopener noreferrer"
rel="noopener nofollow"
className="link author-twitter"
>
{`@${author.twitter}`}
</a>
</span>

)}
{author.personal_link && (
<span className="item">
<a
href={author.personal_link}
target="_blank"
rel="noopener noreferrer"
rel="noopener nofollow"
className="p2 link author-link"
>
{author.link}
Expand All @@ -55,9 +52,7 @@ const AuthorInfo = ({ author }) => {
</div>
<button className="button word-count__button" type="button" onClick={scrollToPosts}>
<p className="p3 word-count" suppressHydrationWarning>
{(author.last_word_count || 0).toLocaleString()}
{" "}
words
{(author.last_word_count || 0).toLocaleString()} words
</p>
<SVG src={IcArrowLong} className="word-count__icon" />
</button>
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/authors/header/menu/AuthorMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const AuthorMenu = ({
{authorHasPages(pages) && pages.map((page) => {
const linkAttrs = page.page_link ? {
target: "_blank",
rel: "noreferrer",
rel: "noreferrer nofollow",
} : {};
return (
<a
Expand Down
11 changes: 3 additions & 8 deletions client/app/components/shared/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ const Footer = ({ blogPage, author, privatePost }) => (
<div className="footer__container">
<p className="p3">Listed Blogging Platform</p>
<p className="p3">
Copyright ©
{" "}
{(new Date()).getFullYear()}
{" "}
{(author && !privatePost) && author.title}
Copyright © {new Date().getFullYear()} {author && !privatePost && author.title}
</p>
<p className="p3">
Via
{" "}
<a href="https://standardnotes.com" target="_blank" rel="noopener noreferrer">
Via{" "}
<a href="https://standardnotes.com" target="_blank" rel="noopener">
Standard Notes
</a>
</p>
Expand Down
13 changes: 2 additions & 11 deletions client/app/components/shared/StartWriting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ const StartWriting = ({ className, children = null }) => {
setIsErrorToastDisplayed(false);

try {
const response = await axios
.post("/authors", null, {
headers: {
"X-CSRF-Token": getAuthToken(),
},
});

Turbolinks.visit(response.request.responseURL);
Turbolinks.visit("new-author");
} catch (err) {
setErrorToastMessage("There was an error trying to generate a new author token for you. Please try again.");
setIsErrorToastDisplayed(true);
Expand All @@ -34,9 +27,7 @@ const StartWriting = ({ className, children = null }) => {
className={`${children ? "button" : "button button--primary"} ${className}`}
type="button"
>
{children || (
"Start writing"
)}
{children || "Start writing"}
</button>
<ErrorToast
message={errorToastMessage}
Expand Down
25 changes: 9 additions & 16 deletions client/app/components/usage/authors_list/AuthorListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,29 @@ const AuthorListItem = ({ author }) => (
{author.id === "easter-egg" ? (
<StartWriting className="easter-egg card">
<div className="active-author__title">
<h5 className="h5">
{author.title}
</h5>
<h5 className="h5">{author.title}</h5>
</div>
<p className="bio active-author__bio p2">{author.bio}</p>
<div className="easter-egg__sign-up">
<p className="p3">
Sign up for Listed
</p>
<p className="p3">Sign up for Listed</p>
<SVG src={IcArrowLong} className="easter-egg__icon--arrow" />
</div>
</StartWriting>
) : (
<div className="card">
<a href={author.url} data-turbolinks="false">
<div className="active-author__title">
<h5 className="h5">
{author.title}
</h5>
<h5 className="h5">{author.title}</h5>
{author.featured && (
<div className="active-author__icon-container">
<SVG src={IcStarCircleFilled} className="active-author__icon active-author__icon--featured" />
<SVG
src={IcStarCircleFilled}
className="active-author__icon active-author__icon--featured"
/>
</div>
)}
</div>
{author.bio
&& <p className="bio active-author__bio p2">{author.bio}</p>}
{author.bio && <p className="bio active-author__bio p2">{author.bio}</p>}
<div className="active-author__word-count">
<SVG src={IcTextRich} className="active-author__icon active-author__icon--word-count" />
<p className="p3 active-author__word-count" suppressHydrationWarning>
Expand All @@ -53,10 +49,7 @@ AuthorListItem.propTypes = {
author: PropTypes.shape({
bio: PropTypes.string,
featured: PropTypes.bool.isRequired,
id: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
title: PropTypes.string.isRequired,
url: PropTypes.string,
last_word_count: PropTypes.number,
Expand Down
14 changes: 9 additions & 5 deletions client/app/components/usage/authors_list/AuthorListItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
color: var(--color-contrast);
font-weight: normal;
margin-top: $spacing-4;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 5;
overflow: hidden;
}

.easter-egg {
Expand All @@ -27,16 +31,16 @@
&:hover {
box-shadow: $spacing-8 $spacing-8 0 var(--color-primary);
background-image: none;

.active-author__title {
color: var(--color-primary);
}

.active-author__icon--featured {
g {
opacity: 1;
}

path {
fill: var(--color-primary);
}
Expand All @@ -49,7 +53,7 @@
margin-bottom: $spacing-24;

@media (max-width: 1311px) {
width: calc((100% - #{$spacing-24} * 2) / 3)
width: calc((100% - #{$spacing-24} * 2) / 3);
}
}
}
Expand Down Expand Up @@ -110,7 +114,7 @@
height: 16px;
width: 16px;
margin-left: $spacing-8;

path {
fill: var(--color-contrast);
}
Expand Down
Loading

0 comments on commit c366bbb

Please sign in to comment.