Skip to content

Commit

Permalink
Added the About page; Added an AuthorImage component for it; Edited a…
Browse files Browse the repository at this point in the history
…ssociated components
  • Loading branch information
joshwingreene committed Mar 15, 2024
1 parent d66ba98 commit 9f0b661
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 37 deletions.
5 changes: 5 additions & 0 deletions content/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
13 changes: 11 additions & 2 deletions quartz.layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const noteOrEssayPageLayout: PageLayout = {
Component.Subtitle(),
Component.TagList(),
Component.Row({
isSpacedBetween: true,
hasSpacedBetweenJustification: true,
components: [
Component.Row({
isSpacedBetween: false,
hasSpacedBetweenJustification: false,
components: [
Component.Author(),
Component.Contributions()
Expand Down Expand Up @@ -64,6 +64,15 @@ export const portfolioItemPageLayout: PageLayout = {

}

export const aboutPageLayout: PageLayout = {
beforeBody: [
Component.Title({ useConfig: true }),
Component.Subtitle({ useConfig: true }),
],
left: [],
right: [],
}

// components for pages that display a single page (e.g. a single note)
export const defaultContentPageLayout: PageLayout = {
beforeBody: [
Expand Down
19 changes: 19 additions & 0 deletions quartz/components/AuthorImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { classNames } from "../util/lang";
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"

export default (() => {
function AuthorImage({ displayClass, cfg }: QuartzComponentProps) {
const { landingPageData: { authorImageUrl, authorName } } = cfg;

return (
<img class={classNames(displayClass, "author-img")} src={`../../static/${authorImageUrl}`} alt={`Photo of ${authorName}`} />
)
}
AuthorImage.css = `
.author-img {
margin: 0;
}
`

return AuthorImage
}) satisfies QuartzComponentConstructor
29 changes: 20 additions & 9 deletions quartz/components/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } fro
import { classNames } from "../util/lang"

interface Options {
isSpacedBetween: boolean
components: QuartzComponent[]
hasSpacedBetweenJustification: boolean
hasFlexStartAlignment?: boolean,
classes?: string[]
}

export default ((opts?: Options) => {
function Row(componentData: QuartzComponentProps) {
const { displayClass } = componentData;
const isSpacedBetween = opts?.isSpacedBetween ? opts.isSpacedBetween : false;
const hasSpacedBetweenJustification = opts?.hasSpacedBetweenJustification ? opts.hasSpacedBetweenJustification : false;
const hasFlexStartAlignment = opts?.hasFlexStartAlignment ? opts.hasFlexStartAlignment : false;
const components = opts?.components;
const classes = opts?.classes ?? [];

if (components) {
return (
<div class={`row ${classNames(displayClass, isSpacedBetween ? "space-between" : "flex-start")}`}>
<div class={`row ${classes.join(" ")}
${classNames(displayClass, hasSpacedBetweenJustification ? "justify-space-between" : "justify-flex-start")}
${classNames(displayClass, hasFlexStartAlignment ? "align-flex-start" : "align-center")}
`}>
{ components.map((Component, i) => <Component {...componentData} key={i} />) }
</div>
)
Expand All @@ -25,17 +32,15 @@ export default ((opts?: Options) => {

Row.css = `
.row {
display: flex;
flex-direction: row;
align-items: center;
margin-top: .5rem;
}
.flex-start {
display: flex;
flex-direction: row;
.justify-flex-start {
justify-content: flex-start;
}
.space-between {
display: flex;
.justify-space-between {
@media only screen and (min-width: 768px) {
flex-direction: row;
justify-content: space-between;
Expand All @@ -48,6 +53,12 @@ export default ((opts?: Options) => {
align-items: flex-start;
}
}
.align-center {
align-items: center;
}
.align-flex-start {
align-items: flex-start;
}
`
return Row
}) satisfies QuartzComponentConstructor
27 changes: 20 additions & 7 deletions quartz/components/Subtitle.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { classNames } from "../util/lang"
import { getWhatIDoStr } from "../util/author";

export default (() => {
interface Options {
useConfig?: boolean
}

export default ((opts?: Options) => {
function Subtitle({ fileData, cfg, displayClass }: QuartzComponentProps) {
const title = fileData.frontmatter?.subtitle
if (title) {
return <h3 class={classNames(displayClass, "subtitle")}>{title}</h3>
} else {
return null
}
const options = opts;
let subtitle = undefined;

if (options && options.useConfig) {
subtitle = getWhatIDoStr(cfg.landingPageData.intro.whatIDo);
} else {
subtitle = fileData.frontmatter?.subtitle;
}

if (subtitle) {
return <h3 class={classNames(displayClass, "subtitle")}>{subtitle}</h3>
} else {
return null
}
}

Subtitle.css = `
Expand Down
39 changes: 26 additions & 13 deletions quartz/components/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { classNames } from "../util/lang"

function Title({ fileData, displayClass }: QuartzComponentProps) {
const title = fileData.frontmatter?.title
interface Options {
useConfig?: boolean
}

export default ((opts?: Options) => {
function Title({ fileData, displayClass, cfg }: QuartzComponentProps) {
const options = opts;
let title = undefined;

if (options && options.useConfig) {
title = cfg.landingPageData.authorName;
} else {
title = fileData.frontmatter?.title;
}

if (title) {
return <h1 class={classNames(displayClass, "title")}>{title}</h1>
} else {
return null
if (title) {
return <h1 class={classNames(displayClass, "title")}>{title}</h1>
} else {
return null
}
}
}
Title.css = `
.title {
margin: 0;
}
`
Title.css = `
.title {
margin: 0;
}
`

export default (() => Title) satisfies QuartzComponentConstructor
return Title
}) satisfies QuartzComponentConstructor
4 changes: 3 additions & 1 deletion quartz/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Author from "./Author"
import CultivationDates from "./CultivationDates"
import RSS from "./RSS"
import SocialIcons from "./SocialIcons"
import AuthorImage from "./AuthorImage"

export {
Title,
Expand Down Expand Up @@ -79,5 +80,6 @@ export {
Author,
CultivationDates,
RSS,
SocialIcons
SocialIcons,
AuthorImage
}
22 changes: 20 additions & 2 deletions quartz/components/renderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { render } from "preact-render-to-string"
import { QuartzComponent, QuartzComponentProps } from "./types"
import HeaderConstructor from "./Header"
import BodyConstructor from "./Body"
import RowConstructor from "./Row"
import AuthorImageConstructor from "./AuthorImage"
import { JSResourceToScriptElement, StaticResources } from "../util/resources"
import { clone, FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path"
import { visit } from "unist-util-visit"
Expand Down Expand Up @@ -214,6 +216,17 @@ export function renderPage(
const lang = componentData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
const LandingComponent = Landing()
const GardenComponent = Garden()
const AuthorImage = AuthorImageConstructor()
const RowComponent = RowConstructor(
{ hasSpacedBetweenJustification: true,
hasFlexStartAlignment: true,
components: [
Content,
AuthorImage
],
classes: ["article-and-author-img"]
}
)

console.log("slug -", slug);

Expand All @@ -232,15 +245,20 @@ export function renderPage(
<Body {...componentData}>
{ (slug !== "index" && slug !== "garden/index") ? LeftComponent : <div></div>}
<div class="center">
{ slug !== "index" && slug !== "garden/index" && (<div class="popover-hint">
{ slug !== "index" && slug !== "garden/index" && (
<div class="popover-hint">
{beforeBody.map((BodyComponent) => (
<BodyComponent {...componentData} />
))}
</div>
)}
{ slug === "index" && <LandingComponent {...componentData} /> }
{ slug === "garden/index" && <GardenComponent {...componentData} /> }
{ (slug !== "index" && slug !== "garden/index") && <Content {...componentData} /> }
{ (slug !== "index" && slug !== "garden/index" && slug !== "about") && <Content {...componentData} /> }
{ slug === "about" && (
<RowComponent {...componentData} />
)
}
</div>
{ (slug !== "index" && slug !== "garden/index") ? RightComponent : <div></div> }
</Body>
Expand Down
15 changes: 13 additions & 2 deletions quartz/plugins/emitters/contentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ import DarkModeConstructor from "../../components/Darkmode"
import RSSConstructor from "../../components/RSS"
import SocialIconsConstructor from "../../components/SocialIcons"
import ContributionsConstructor from "../../components/Contributions"
import AuthorImageConstructor from "../../components/AuthorImage"
import { pageResources, renderPage } from "../../components/renderPage"
import { FullPageLayout } from "../../cfg"
import { Argv } from "../../util/ctx"
import { FilePath, isRelativeURL, joinSegments, pathToRoot } from "../../util/path"
import { defaultContentPageLayout, sharedPageComponents, noteOrEssayPageLayout, portfolioItemPageLayout } from "../../../quartz.layout"
import {
defaultContentPageLayout,
sharedPageComponents,
noteOrEssayPageLayout,
portfolioItemPageLayout,
aboutPageLayout
} from "../../../quartz.layout"
import { Content } from "../../components"
import chalk from "chalk"
import { write } from "./helpers"
Expand Down Expand Up @@ -102,6 +109,7 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
const RSS = RSSConstructor()
const SocialIcons = SocialIconsConstructor()
const Contributions = ContributionsConstructor()
const AuthorImage = AuthorImageConstructor()

return {
name: "ContentPage",
Expand All @@ -112,7 +120,8 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
Garden, Card, RecentlyPublished,
GrowthStage, Row, Author, CultivationDates, Contributions,
Team, ToolsOrTech, Role, Duration, Grid, Divider,
Search, DarkMode, RSS, SocialIcons
Search, DarkMode, RSS, SocialIcons,
AuthorImage
]
},
async getDependencyGraph(ctx, content, _resources) {
Expand Down Expand Up @@ -158,6 +167,8 @@ export const ContentPage: QuartzEmitterPlugin<Partial<FullPageLayout>> = (userOp
newOpts = { ...opts, ...noteOrEssayPageLayout }
} else if (slug.includes("portfolio/")) {
newOpts = { ...opts, ...portfolioItemPageLayout }
} else if (slug.includes("about")) {
newOpts = { ...opts, ...aboutPageLayout }
}

const content = renderPage(cfg, slug, componentData, newOpts ?? opts, externalResources)
Expand Down
16 changes: 16 additions & 0 deletions quartz/styles/custom.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@use "./base.scss";

// put your custom CSS here!

.article-and-author-img {
article {
flex: 2;
}

img {
@media only screen and (min-width: 768px) {
flex: 1;
}

@media only screen and (max-width: 768px) {
width: 100%;
}
}
}
5 changes: 4 additions & 1 deletion quartz/util/author.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Function that gets the initials of the name
export function getInitials(name: string) {
let initials = name.match(/\b\w/g) || []
return ((initials.shift() || '') + (initials.pop() || '')).toUpperCase()
}

export function getWhatIDoStr(whatIDoArray: string[]) {
return `${whatIDoArray.slice(0, whatIDoArray.length - 1).join(", ")}, and a ${ whatIDoArray[whatIDoArray.length - 1]}`
}

0 comments on commit 9f0b661

Please sign in to comment.