Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate project description to prevent title overlapping #140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,33 @@ export const customPageView = (url: string) => {
export const customOutboundLink = (url: string) => {
if (develop || local) {
const link = document.createElement("a");
link.setAttribute("href", url);
link.target = "_blank";
link.style.display = "none";
link.setAttribute('rel','noopener noreferrer')
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link.setAttribute("href", url);
link.target = "_blank";
link.style.display = "none";
link.setAttribute('rel', 'noopener noreferrer')
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
outboundLink({ label: url }, () => {
const link = document.createElement("a");
link.setAttribute("href", url);
link.target = "_blank";
link.style.display = "none";
link.setAttribute('rel','noopener noreferrer')
link.setAttribute('rel', 'noopener noreferrer')
document.body.appendChild(link);
link.click();
document.body.removeChild(link)
});
});
}
};

export const truncate = (text: string, limit: number, suffix: string) => {
let content: string[]
text = text.trim();
// convert the text into a array of words and remove words beyond the limit
content = text.split(' ').slice(0, limit);

text = content.join(' ') + (suffix ? suffix : '');
return text;
}
4 changes: 2 additions & 2 deletions src/routes/Projects/components/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FixMeFooter from "../../../components/FixMeFooter/FixMeFooter";
import FixMeMetas from "../../../components/FixMeMetas/FixMeMetas";
import FixMeNavbar from "../../../components/FixMeNavbar/FixMeNavbar";
import { shade } from "../../../helpers/colors";
import { customPageView } from "../../../helpers/helpers";
import { customPageView, truncate } from "../../../helpers/helpers";
import notfound from '../../../images/notfound.png';
import "../../../styles/projects.css";
import { IProject } from "../modules/projectReducer";
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class Projects extends React.PureComponent<IProjectProps, {}> {
</div>
<div className="projects-description">
<p className="projects-description-text">
{description}
{truncate(description, 30, "...")}
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/projects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $opacity: 0.3;
z-index: 2;
}
&-top-title {
font-size: 1.8em;
font-size: 1.5em;
line-height: 1em;
margin-top: 0;
text-align: left;
Expand Down