From 182cbca3c33e9342431eb54d9462f455d116f0a4 Mon Sep 17 00:00:00 2001
From: Mohamed El Mahallawy
Date: Tue, 5 Apr 2016 23:14:03 -0700
Subject: [PATCH] Meta tags update
---
server.js | 9 +++++++
src/containers/Surah/index.js | 49 +++++++++++++++++++++++++++++++----
src/helpers/makeHeadTags.js | 39 ++++++++++++++++++++++++++++
3 files changed, 92 insertions(+), 5 deletions(-)
create mode 100644 src/helpers/makeHeadTags.js
diff --git a/server.js b/server.js
index 22cc88fcc..09b071c1c 100644
--- a/server.js
+++ b/server.js
@@ -41,6 +41,15 @@ server.use((req, res, next) => {
webpack_isomorphic_tools.refresh()
}
+ if (req.query.DISABLE_SSR) {
+ return res.status(200).send('\n' + ReactDOM.renderToString(
+
+ ));
+ }
+
store.dispatch(setUserAgent(req.useragent));
store.dispatch(setOption(cookie.load('options') || {}));
diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js
index afdeed84a..c0bb70b5d 100644
--- a/src/containers/Surah/index.js
+++ b/src/containers/Surah/index.js
@@ -22,6 +22,9 @@ import Line from 'components/surah/Line';
import SearchInput from 'components/header/SearchInput';
import Bismillah from '../../components/Bismillah';
+// Helpers
+import makeHeadTags from '../../helpers/makeHeadTags';
+
import debug from 'utils/Debug';
import { clearCurrent, isLoaded, load as loadAyahs } from '../../redux/modules/ayahs';
@@ -86,8 +89,8 @@ let lastScroll = 0;
])
@connect(
(state, ownProps) => {
- const surah = state.surahs.entities[ownProps.params.surahId];
- const ayahs = state.ayahs.entities[ownProps.params.surahId];
+ const surah: Object = state.surahs.entities[ownProps.params.surahId];
+ const ayahs: Object = state.ayahs.entities[ownProps.params.surahId];
const ayahIds = new Set(Object.keys(ayahs).map(key => parseInt(key.split(':')[1], 10)));
ayahIds.first = function() {return [...this][0];};
ayahIds.last = function() {return [...this][[...this].length - 1];};
@@ -152,6 +155,35 @@ export default class Surah extends Component {
}
}
+ title() {
+ const { params, surah } = this.props;
+
+ if (params.range) {
+ return `Surat ${surah.name.simple} [${surah.id}:${params.range}]`;
+ }
+
+ return `Surat ${surah.name.simple}`;
+ }
+
+ description() {
+ const { params, ayahs, surah } = this.props;
+
+ if (params.range) {
+ if (params.range.includes('-')) {
+ const [from, to] = params.range.split('-').map(num => parseInt(num, 10));
+ const array = Array(to - from).fill(from);
+ const translations = array.map((fromAyah, index) => ayahs[`${surah.id}:${fromAyah + index}`].content[0].text);
+ const content = translations.join(' - ').slice(0, 250);
+
+ return `Surat ${surah.name.simple} [verse ${params.range}] - ${content}`;
+ } else {
+ return `Surat ${surah.name.simple} [verse ${params.range}] - ${ayahs[`${surah.id}:${params.range}`].content[0].text}`;
+ }
+ }
+
+ return null;
+ }
+
renderPagination() {
const { isEndOfSurah, surah } = this.props;
const { lazyLoading } = this.state;
@@ -323,9 +355,16 @@ export default class Surah extends Component {
return (
-
+