Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Next.js built chunks
(window.webpackJsonp = window.webpackJsonp || []).push([
[21], {
"+51p": function(t, n, e) {
"use strict";
e.r(n), e.d(n, "__N_SSP", (function() {
return m
}));
var o = e("q1tI"),
r = e.n(o),
c = e("8Kt/"),
i = e.n(c),
a = e("5Yp1"),
u = e("AWWZ"),
l = e("yLiY"),
p = e.n(l),
s = e("YFqc"),
d = e.n(s),
f = (e("GjN9"), e("AFQm")),
b = r.a.createElement,
g = p()().publicRuntimeConfig,
_ = function(t) {
return "".concat("tip" === t.type ? "Tips" : "Hj\xe4lpf\xf6rfr\xe5gan", " i ").concat(Object(f.b)(t.location).name, " - Hj\xe4ltehj\xe4lpen - Aftonbladet")
},
w = function(t) {
return "".concat(t.description.substr(0, 55), "...")
},
y = function(t) {
return "".concat(g.BASE_URL, "/share/").concat(t.request_id)
};
var m = !0;
n.default = Object(a.a)((function(t) {
var n = t.router,
e = t.cards,
o = t.locations;
return t.id, console.log(y(e[0])), b(r.a.Fragment, null, b(i.a, null, b("meta", {
property: "og:title",
content: _(e[0]),
key: "ogTitle"
}), b("meta", {
property: "og:description",
content: w(e[0]),
key: "ogDescription"
}), b("meta", {
property: "og:url",
content: y(e[0]),
key: "ogUrl"
})), b(u.a, {
router: n,
cards: e,
locations: o,
heroCard: !0,
hideFilter: !0
}), b(d.a, {
href: "/all"
}, b("button", {
type: "button",
className: "btn-circle btn-circle--grey"
}, "VISA ALLA")))
}))
},
LK7L: function(t, n, e) {
(window.__NEXT_P = window.__NEXT_P || []).push(["/share/[id]", function() {
return e("+51p")
}])
}
},
[
["LK7L", 0, 2, 4, 1, 3, 6, 7, 8, 5]
]
]);
import Head from 'next/head';
import withLayout from '../../components/Layout';
import VisibleCards from '../../components/Listing/visibleCards';
import fetch from 'node-fetch';
import getConfig from 'next/config';
import Link from 'next/link'
import '../../components/Listing/Cards.css';
import { regionById } from '../../lib/regions';
const postsToShow = 4;
const { publicRuntimeConfig } = getConfig();
const { BASE_URL } = publicRuntimeConfig;
const shareTitleGenerator = (request) => `${request.type === 'tip' ? 'Tips' : 'Hjälpförfrågan'} i ${regionById(request.location).name} - Hjältehjälpen - Aftonbladet`;
const shareDescriptionGenerator = (request) => `${request.description.substr(0, 55)}...`;
const shareUrlGenerator = (request) => `${publicRuntimeConfig.BASE_URL}/share/${request.request_id}`;
function Share({ router, cards, locations, id }) {
console.log(shareUrlGenerator(cards[0]));
return (
<>
<Head>
{ /* Override meta */ }
<meta property="og:title" content={shareTitleGenerator(cards[0])} key="ogTitle"/>
<meta property="og:description" content={shareDescriptionGenerator(cards[0])} key="ogDescription"/>
<meta property="og:url" content={shareUrlGenerator(cards[0])} key="ogUrl"/>
</Head>
<VisibleCards router={router} cards={cards} locations={locations} heroCard hideFilter />
<Link href="/all">
<button type="button" className='btn-circle btn-circle--grey'>
VISA ALLA
</button>
</Link>
</>
);
}
export async function getServerSideProps({ res, query }) {
let cards;
res.setHeader('Cache-control', 'public, max-age=60');
const queryToken = query;
const { id } = queryToken;
const resLocations = [];
const resCards = await fetch(`${BASE_URL}/api/share?limit=${postsToShow}&id=${id}`).catch(error => console.error('Failed to fetch cards', error));
if (!resCards) {
cards = [];
} else {
cards = await resCards.json().catch((err) => {
console.error('Failed to parse cards', err);
return [];
});
}
return {
props: {
locations: [],
cards,
id
},
}
}
export default withLayout(Share);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment