Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #298 from 30-seconds/collection-images
Browse files Browse the repository at this point in the history
Resolves #238
  • Loading branch information
Chalarangelo committed Jan 28, 2021
2 parents 56dd025 + ee48742 commit 910dc52
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/blocks/adapters/snippetCollectionListing/index.js
Expand Up @@ -48,6 +48,10 @@ export class SnippetCollectionListing {
return this.snippetCollection.description;
}

get listingImage() {
return this.snippetCollection.splash;
}

get listingSublinks() {
if (this.snippetCollection.type === 'blog') {
return [];
Expand Down Expand Up @@ -80,6 +84,7 @@ export class SnippetCollectionListing {
'listingName',
'listingTitle',
'listingDescription',
'listingImage',
'listingType',
'listingSublinks',
'pageDescription',
Expand Down
34 changes: 34 additions & 0 deletions src/blocks/entities/snippetCollection/index.js
Expand Up @@ -239,6 +239,40 @@ export class SnippetCollection {
return this._description;
}

get splash() {
if (!this._splash) {
switch (this.type) {
case 'main':
this._splash = null;
break;
case 'blog':
this._splash = null;
break;
case 'language':
this._splash = this.config.splash
? `${this.config.assetPath}/${this.config.splash}`
: null;
break;
case 'tag':
this._splash =
this.tagMetadata && this.tagMetadata.splash
? `${this.config.assetPath}/${this.tagMetadata.splash}`
: this.config.splash
? `${this.config.assetPath}/${this.config.splash}`
: null;
break;
case 'collection':
this._splash = this.config.splash
? `${this.config.assetPath}/${this.config.splash}`
: null;
break;
default:
break;
}
}
return this._splash;
}

get seoDescription() {
if (!this._seoDescription) {
this._seoDescription = literals.listing.pageDescription(this.type, {
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/serializers/asset/index.js
Expand Up @@ -42,6 +42,7 @@ export class AssetSerializer {
const boundLog = Logger.bind('serializers.asset.serialize');
const {
rawAssetPath: inPath,
rawContentAssetPath: inContentPath,
assetPath: outPath,
rawContentPath: contentPath,
staticAssetPath: staticAssetPath,
Expand All @@ -57,6 +58,7 @@ export class AssetSerializer {
);
fs.ensureDirSync(outPath);
await fs.copy(inPath, outPath);
await fs.copy(inContentPath, outPath);
boundLog('Static assets have been copied', 'success');

boundLog(`Processing image assets from configuration files`, 'info');
Expand Down
7 changes: 6 additions & 1 deletion src/components/molecules/listingAnchors/_index.scss
Expand Up @@ -59,7 +59,7 @@
min-width: 100%;
padding: 0.375rem 0.25rem;
line-height: 1.5rem;
height: 48px;
height: 40px;
border: none;
box-shadow: none;
text-align: center;
Expand All @@ -80,6 +80,11 @@

@media screen and (min-width: $layout-medium-breakpoint) {
padding: 0.625rem 0.875rem;
height: 48px;
}

@media screen and (min-width: $layout-large-breakpoint) {
height: 52px;
}
}
}
37 changes: 37 additions & 0 deletions src/components/organisms/snippetList/_index.scss
Expand Up @@ -13,12 +13,49 @@
}
}

.snippet-list-header {

&.with-image {

.page-title {
display: block;
text-align: center;
}

@media screen and (min-width: $layout-medium-breakpoint) {
display: grid;
grid-template-columns: auto 240px;
align-items: center;
min-height: 340px;

.page-title {
text-align: left;
}
}

@media screen and (min-width: $layout-large-breakpoint) {
min-height: 300px;
grid-template-columns: auto 360px;
}
}
}

.snippet-list-description {
margin: 1rem 0.875rem 0.5rem;
line-height: 2;
color: var(--fore-color);
}

.snippet-list-splash-image {
margin: 0.5rem 0.875rem 0.5rem;
width: calc(100% - 1.75rem);
max-height: 25vh;

@media screen and (min-width: $layout-medium-breakpoint) {
order: 2;
}
}

.snippet-list-controls {
margin: 0.25rem 0.875rem 1.5rem;
display: grid;
Expand Down
31 changes: 25 additions & 6 deletions src/components/organisms/snippetList/index.jsx
Expand Up @@ -5,13 +5,15 @@ import Sorter from 'components/molecules/sorter';
import PageTitle from 'components/atoms/pageTitle';
import PreviewCard from 'components/molecules/previewCard';
import ListingAnchors from 'components/molecules/listingAnchors';
import combineClassNames from '@chalarangelo/combine-class-names';

const propTypes = {
snippetList: PropTypes.arrayOf(PropTypes.snippet),
paginator: PropTypes.paginator,
sorter: PropTypes.sorter,
listingName: PropTypes.string,
listingDescription: PropTypes.string,
listingImage: PropTypes.string,
listingType: PropTypes.string,
listingSublinks: PropTypes.arrayOf(PropTypes.shape({})),
};
Expand All @@ -27,11 +29,11 @@ const SnippetList = ({
sorter,
listingName,
listingDescription = '',
listingImage = '',
listingType,
listingSublinks = [],
}) => {
/* istanbul ignore next */
const ctaIndex = 4;
const isMainOrBlogListing = listingType === 'main' || listingType === 'blog';
const withSorter = sorter && sorter.orders && sorter.orders.length > 1;

Expand All @@ -46,10 +48,27 @@ const SnippetList = ({
</>
) : (
<>
<PageTitle>{listingName}</PageTitle>
{listingDescription && listingDescription.length ? (
<p className='snippet-list-description'>{listingDescription}</p>
) : null}
<div
className={combineClassNames`snippet-list-header ${
listingImage ? 'with-image' : ''
}`}
>
{listingImage ? (
<img
className='snippet-list-splash-image'
src={listingImage}
alt=''
height='360'
width='360'
/>
) : null}
<div>
<PageTitle>{listingName}</PageTitle>
{listingDescription && listingDescription.length ? (
<p className='snippet-list-description'>{listingDescription}</p>
) : null}
</div>
</div>
<div className='snippet-list-controls'>
{listingSublinks.length ? (
<ListingAnchors items={listingSublinks} />
Expand All @@ -61,7 +80,7 @@ const SnippetList = ({
<ul className='snippet-list'>
{snippetList.map(snippet => (
<PreviewCard key={`snippet_${snippet.url}`} snippet={snippet} />
))}
))}
</ul>
<Paginator paginator={paginator} />
</>
Expand Down
3 changes: 3 additions & 0 deletions src/components/templates/listingPage/index.jsx
Expand Up @@ -12,6 +12,7 @@ const propTypes = {
listingName: PropTypes.string,
listingTitle: PropTypes.string,
listingDescription: PropTypes.string,
listingImage: PropTypes.string,
listingType: PropTypes.string,
listingSublinks: PropTypes.arrayOf(PropTypes.shape({})),
pageDescription: PropTypes.string.isRequired,
Expand All @@ -31,6 +32,7 @@ const ListingPage = ({
listingName,
listingTitle,
listingDescription,
listingImage,
listingType,
listingSublinks = [],
pageDescription,
Expand All @@ -53,6 +55,7 @@ const ListingPage = ({
<SnippetList
listingName={listingTitle}
listingDescription={listingDescription}
listingImage={listingImage}
listingType={listingType}
snippetList={snippetList}
paginator={paginator}
Expand Down
1 change: 1 addition & 0 deletions src/settings/paths.json
Expand Up @@ -2,6 +2,7 @@
"settingsPath": "src/settings/!(global|paths).json",
"assetPath": ".assets",
"rawAssetPath": "assets",
"rawContentAssetPath": "content/configs/assets",
"staticAssetPath": "assets",
"contentPath": ".content",
"rawContentPath": "content",
Expand Down

0 comments on commit 910dc52

Please sign in to comment.