mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-06 16:06:12 +02:00
feat: support external resources (#50)
feat: support external resources
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from "react"
|
import React, { Fragment } from "react"
|
||||||
|
|
||||||
import { StackedAvatars } from "../StackedAvatars"
|
import { StackedAvatars } from "../StackedAvatars"
|
||||||
import ChevronUp from "../../icons/chevron-up.svg"
|
import ChevronUp from "../../icons/chevron-up.svg"
|
||||||
@@ -10,6 +10,35 @@ interface ResourceHeaderProps {
|
|||||||
createdAt: any
|
createdAt: any
|
||||||
timeToRead: any
|
timeToRead: any
|
||||||
recommendedReading: any
|
recommendedReading: any
|
||||||
|
externalResources: any
|
||||||
|
}
|
||||||
|
|
||||||
|
function ExtraLink({
|
||||||
|
item,
|
||||||
|
external = false,
|
||||||
|
}: {
|
||||||
|
item: string
|
||||||
|
external?: boolean
|
||||||
|
}) {
|
||||||
|
const Inner = () => (
|
||||||
|
<Fragment>
|
||||||
|
<ChevronUp /> <SC.ExtraLinkText>{item}</SC.ExtraLinkText>
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (external) {
|
||||||
|
return (
|
||||||
|
<SC.ExtraLinkExternal href={item} target="_blank">
|
||||||
|
<Inner />
|
||||||
|
</SC.ExtraLinkExternal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SC.ExtraLinkInternal to={`/resources/${item}.md`}>
|
||||||
|
<Inner />
|
||||||
|
</SC.ExtraLinkInternal>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ResourceHeader({
|
export function ResourceHeader({
|
||||||
@@ -18,6 +47,7 @@ export function ResourceHeader({
|
|||||||
createdAt,
|
createdAt,
|
||||||
timeToRead,
|
timeToRead,
|
||||||
recommendedReading,
|
recommendedReading,
|
||||||
|
externalResources,
|
||||||
}: ResourceHeaderProps) {
|
}: ResourceHeaderProps) {
|
||||||
const date = new Date(createdAt)
|
const date = new Date(createdAt)
|
||||||
const month = date.toLocaleString("default", { month: "long" })
|
const month = date.toLocaleString("default", { month: "long" })
|
||||||
@@ -44,14 +74,19 @@ export function ResourceHeader({
|
|||||||
<SC.RecommendedReading>
|
<SC.RecommendedReading>
|
||||||
Recommended reading
|
Recommended reading
|
||||||
{recommendedReading.map(item => {
|
{recommendedReading.map(item => {
|
||||||
return (
|
return <ExtraLink item={item} />
|
||||||
<SC.ReadLink>
|
|
||||||
<ChevronUp /> <SC.ReadLinkText>{item}</SC.ReadLinkText>
|
|
||||||
</SC.ReadLink>
|
|
||||||
)
|
|
||||||
})}
|
})}
|
||||||
</SC.RecommendedReading>
|
</SC.RecommendedReading>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{externalResources && (
|
||||||
|
<SC.ExternalResources>
|
||||||
|
External Resources
|
||||||
|
{externalResources.map(item => {
|
||||||
|
return <ExtraLink item={item} external />
|
||||||
|
})}
|
||||||
|
</SC.ExternalResources>
|
||||||
|
)}
|
||||||
</SC.ResourceHeaderWrapper>
|
</SC.ResourceHeaderWrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import styled from "styled-components"
|
import styled, { css } from "styled-components"
|
||||||
|
import { Link } from "gatsby"
|
||||||
import { fontFamily, modularScale } from "../../design/typography"
|
import { fontFamily, modularScale } from "../../design/typography"
|
||||||
|
|
||||||
export const ResourceHeaderWrapper = styled.div`
|
export const ResourceHeaderWrapper = styled.div`
|
||||||
@@ -26,11 +27,15 @@ export const Meta = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export const RecommendedReading = styled.div`
|
const ExtraLinks = styled.div`
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
`
|
`
|
||||||
|
|
||||||
export const ReadLink = styled.div`
|
export const RecommendedReading = styled(ExtraLinks)``
|
||||||
|
|
||||||
|
export const ExternalResources = styled(ExtraLinks)``
|
||||||
|
|
||||||
|
const extraLink = css`
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: #04b0a6;
|
color: #04b0a6;
|
||||||
@@ -53,6 +58,14 @@ export const ReadLink = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export const ReadLinkText = styled.div`
|
export const ExtraLinkInternal = styled(Link)`
|
||||||
|
${extraLink};
|
||||||
|
`
|
||||||
|
|
||||||
|
export const ExtraLinkExternal = styled.a`
|
||||||
|
${extraLink};
|
||||||
|
`
|
||||||
|
|
||||||
|
export const ExtraLinkText = styled.div`
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -3,6 +3,15 @@ authors:
|
|||||||
- "supergrecko#3434"
|
- "supergrecko#3434"
|
||||||
created_at: "2019/07/27"
|
created_at: "2019/07/27"
|
||||||
title: Singletons
|
title: Singletons
|
||||||
|
external_resources:
|
||||||
|
- https://en.wikipedia.org/wiki/Singleton_pattern
|
||||||
|
- https://phpenthusiast.com/blog/the-singleton-design-pattern-in-php
|
||||||
|
- https://phptherightway.com/pages/Design-Patterns.html#singleton
|
||||||
|
- https://www.php.net/manual/en/language.oop5.static.php
|
||||||
|
- https://www.php.net/manual/en/language.oop5.late-static-bindings.php
|
||||||
|
- https://en.wikipedia.org/wiki/Static_(keyword)
|
||||||
|
- https://en.wikipedia.org/wiki/Null_coalescing_operator
|
||||||
|
- https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
|
||||||
---
|
---
|
||||||
|
|
||||||
A singleton is a class which is only instantiated once during runtime. This is done by keeping a static property containing its instance on the singleton class.
|
A singleton is a class which is only instantiated once during runtime. This is done by keeping a static property containing its instance on the singleton class.
|
||||||
@@ -91,24 +100,3 @@ $first->setWord("Banana");
|
|||||||
// the test will still pass, because it's a singleton.
|
// the test will still pass, because it's a singleton.
|
||||||
var_dump($first->getWord() === $second->getWord()); // bool(true)
|
var_dump($first->getWord() === $second->getWord()); // bool(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Further Research
|
|
||||||
|
|
||||||
Here's a couple links which will help you understand Singletons better.
|
|
||||||
|
|
||||||
## Singleton Resources:
|
|
||||||
|
|
||||||
- https://en.wikipedia.org/wiki/Singleton_pattern
|
|
||||||
- https://phpenthusiast.com/blog/the-singleton-design-pattern-in-php
|
|
||||||
- https://phptherightway.com/pages/Design-Patterns.html#singleton
|
|
||||||
|
|
||||||
## Static Keyword Resources:
|
|
||||||
|
|
||||||
- https://www.php.net/manual/en/language.oop5.static.php
|
|
||||||
- https://www.php.net/manual/en/language.oop5.late-static-bindings.php
|
|
||||||
- https://en.wikipedia.org/wiki/Static_(keyword)
|
|
||||||
|
|
||||||
## The Null-Coalescing Operator Resources:
|
|
||||||
|
|
||||||
- https://en.wikipedia.org/wiki/Null_coalescing_operator
|
|
||||||
- https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ function LanguagePost({ data }: any) {
|
|||||||
createdAt={frontmatter.created_at}
|
createdAt={frontmatter.created_at}
|
||||||
timeToRead={timeToRead}
|
timeToRead={timeToRead}
|
||||||
recommendedReading={frontmatter.recommended_reading}
|
recommendedReading={frontmatter.recommended_reading}
|
||||||
|
externalResources={frontmatter.external_resources}
|
||||||
/>
|
/>
|
||||||
<Markdown content={html} />
|
<Markdown content={html} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
@@ -41,6 +42,7 @@ export const query = graphql`
|
|||||||
created_at
|
created_at
|
||||||
title
|
title
|
||||||
recommended_reading
|
recommended_reading
|
||||||
|
external_resources
|
||||||
}
|
}
|
||||||
timeToRead
|
timeToRead
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user