Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "20190303更新"" #596

Merged
merged 1 commit into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/accountInfo/accountInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { dbCompanies } from '/db/dbCompanies';
import { dbEmployees } from '/db/dbEmployees';
import { dbVips } from '/db/dbVips';
import { roleDisplayName, getManageableRoles } from '/db/users';
import { setPrerenderTitleReady } from '/client/utils/prerenderReady';

import { inheritedShowLoadingOnSubscribing } from '../layout/loading';
import { alertDialog } from '../layout/alertDialog';
import { shouldStopSubscribe } from '../utils/idle';
Expand Down Expand Up @@ -40,6 +42,10 @@ Template.accountInfo.onCreated(function() {
const user = paramUser();
if (user) {
DocHead.setTitle(getCurrentPageFullTitle(user.profile.name));
setPrerenderTitleReady(true);
}
else {
setPrerenderTitleReady(false);
}
});
});
Expand Down
6 changes: 6 additions & 0 deletions client/company/companyDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DocHead } from 'meteor/kadira:dochead';
import { Template } from 'meteor/templating';

import { getCurrentPageFullTitle } from '/routes';
import { setPrerenderTitleReady } from '/client/utils/prerenderReady';

import { inheritedShowLoadingOnSubscribing } from '../layout/loading';
import { paramCompany, paramCompanyId } from './helpers';

Expand All @@ -12,6 +14,10 @@ Template.companyDetail.onCreated(function() {
const company = paramCompany();
if (company) {
DocHead.setTitle(getCurrentPageFullTitle(company.companyName));
setPrerenderTitleReady(true);
}
else {
setPrerenderTitleReady(false);
}
});

Expand Down
6 changes: 6 additions & 0 deletions client/foundation/foundationDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getCurrentPageFullTitle } from '/routes';
import { dbLog } from '/db/dbLog';
import { dbVariables } from '/db/dbVariables';
import { formatShortDateTimeText } from '/common/imports/utils/formatTimeUtils';
import { setPrerenderTitleReady } from '/client/utils/prerenderReady';

import { inheritedShowLoadingOnSubscribing } from '../layout/loading';
import { shouldStopSubscribe } from '../utils/idle';
import { investFoundCompany, markCompanyIllegal, unmarkCompanyIllegal, changeCompanyName } from '../utils/methods';
Expand All @@ -25,6 +27,10 @@ Template.foundationDetail.onCreated(function() {
const foundationData = paramFoundation();
if (foundationData) {
DocHead.setTitle(getCurrentPageFullTitle(foundationData.companyName));
setPrerenderTitleReady(true);
}
else {
setPrerenderTitleReady(false);
}
});

Expand Down
5 changes: 3 additions & 2 deletions client/layout/loading.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { setPrerenderDataReady } from '/client/utils/prerenderReady';

const isLoading = new ReactiveVar(false);
let taskCount = 0;
export function addTask() {
taskCount += 1;
isLoading.set(true);
window.prerenderReady = false;
setPrerenderDataReady(false);
}
export function resolveTask() {
taskCount -= 1;
if (taskCount <= 0) {
isLoading.set(false);
window.prerenderReady = true;
setPrerenderDataReady(true);
}
}
export function inheritedShowLoadingOnSubscribing(template) {
Expand Down
6 changes: 6 additions & 0 deletions client/ruleDiscuss/ruleAgendaDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { dbRound } from '/db/dbRound';
import { dbRuleAgendas } from '/db/dbRuleAgendas';
import { dbRuleIssues } from '/db/dbRuleIssues';
import { dbRuleIssueOptions } from '/db/dbRuleIssueOptions';
import { setPrerenderTitleReady } from '/client/utils/prerenderReady';

import { inheritedShowLoadingOnSubscribing } from '../layout/loading';
import { alertDialog } from '../layout/alertDialog';
import { shouldStopSubscribe } from '../utils/idle';
Expand All @@ -25,6 +27,10 @@ Template.ruleAgendaDetail.onCreated(function() {
const agendaData = dbRuleAgendas.findOne(agendaId);
if (agendaData) {
DocHead.setTitle(getCurrentPageFullTitle(agendaData.title));
setPrerenderTitleReady(true);
}
else {
setPrerenderTitleReady(false);
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions client/ruleDiscuss/ruleAgendaVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { dbRound } from '/db/dbRound';
import { dbRuleAgendas } from '/db/dbRuleAgendas';
import { dbRuleIssues } from '/db/dbRuleIssues';
import { dbRuleIssueOptions } from '/db/dbRuleIssueOptions';
import { setPrerenderTitleReady } from '/client/utils/prerenderReady';

import { inheritedShowLoadingOnSubscribing } from '../layout/loading';
import { alertDialog } from '../layout/alertDialog';
import { shouldStopSubscribe } from '../utils/idle';
Expand All @@ -24,6 +26,10 @@ Template.ruleAgendaVote.onCreated(function() {
const agendaData = dbRuleAgendas.findOne(agendaId);
if (agendaData) {
DocHead.setTitle(getCurrentPageFullTitle(agendaData.title));
setPrerenderTitleReady(true);
}
else {
setPrerenderTitleReady(false);
}
}
});
Expand Down
41 changes: 41 additions & 0 deletions client/utils/prerenderReady.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getCurrentPage } from '/routes';

let prerenderDataReady = false;
let prerenderTitleReady = false;

export function setPrerenderDataReady(ready) {
prerenderDataReady = ready;
setPrerenderReady();
}

export function setPrerenderTitleReady(ready) {
prerenderTitleReady = ready;
setPrerenderReady();
}


function setPrerenderReady() {
window.prerenderReady = isPrerenderReady();
}

function isPrerenderReady() {
if (! prerenderDataReady) {
return false;
}

if (isNeedResetTitlePage() && (! prerenderTitleReady)) {
return false;
}

return true;
}

const resetTitlePageList = ['companyDetail', 'accountInfo', 'foundationDetail', 'ruleAgendaDetail', 'ruleAgendaVote'];
function isNeedResetTitlePage() {
if (resetTitlePageList.includes(getCurrentPage())) {
return true;
}
else {
return false;
}
}
9 changes: 9 additions & 0 deletions server/startup/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import { WebApp } from 'meteor/webapp';
Meteor.startup(() => {
prerenderNode.set('protocol', 'https');
prerenderNode.set('prerenderServiceUrl', getPrerenderServer());
prerenderNode.set('crawlerUserAgents', [
'googlebot',
'Yahoo! Slurp',
'bingbot',
'yandex',
'baiduspider',
'developers.google.com/+/web/snippet',
'Applebot'
]);
WebApp.rawConnectHandlers.use(prerenderNode);
});

Expand Down