Skip to content

Commit

Permalink
Merge pull request #192 from watchout-tw/staging
Browse files Browse the repository at this point in the history
v2.0.0 專題套版功能
  • Loading branch information
wesley100002001 authored Nov 7, 2024
2 parents d4084b2 + 2f18315 commit 566f1b2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion components/FooterStandard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const linkGroups = [
links: [
{
title: 'English',
url: getBaseURL('watchout') + '?lang=en',
url: getBaseURL() + '?lang=en',
relative: false
},
{
Expand Down
28 changes: 6 additions & 22 deletions interfaces/knowsWatchout.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,21 @@ export default {
getBaseURL,
getCompDocURL,
getCompVideoURL,
getLabRepURL(repID) {
return this.getBaseURL('lab') + `reps/${repID}`
},
getAskGameURL(gameSlug) {
return this.getBaseURL('ask') + `games/${gameSlug}`
},
getAskQuestionURL(gameSlug, questionID) {
return this.getBaseURL('ask') + `games/${gameSlug}/questions/${questionID}`
},
getAskAnswerURL(gameSlug, answerID) {
return this.getBaseURL('ask') + `games/${gameSlug}/answers/${answerID}`
},
getPersonaProfileURL(personaID) {
return this.getBaseURL('watchout') + `authors/${personaID}`
},
getParkSettingsURL() {
return this.getBaseURL('park') + 'settings'
return this.getBaseURL() + `authors/${personaID}`
},
getWatchoutDocListURL() {
return this.getBaseURL('watchout') + 'docs'
return this.getBaseURL() + 'docs'
},
getWatchoutProjectURL,
getWatchoutNewsletterURL(id) {
return this.getBaseURL('watchout') + 'news/' + id
return this.getBaseURL() + 'news/' + id
},
getWatchoutMemberInfoURL() {
return this.getBaseURL('watchout') + 'member'
return this.getBaseURL() + 'member'
},
// TODO: Remove channelID
generateMeta(channelID, pageTitle, pageDescription, image) {
let baseURL = this.getBaseURL(channelID)
generateMeta(pageTitle, pageDescription, image) {
let baseURL = this.getBaseURL()
if(!image) {
image = defaultImage
}
Expand Down
36 changes: 35 additions & 1 deletion lib/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,30 @@ async function getProjects({ pubDest = '*', activeOnly = true, desc = true, tagI
return projects
}

async function getProject(id) {
async function getProject(id, withContent = false) {
let snapshot = await bunkoFS.collection('projects').doc(id).get()
let project = null
if(snapshot && snapshot.id && snapshot.data()) {
project = Object.assign(snapshot.data(), { id: snapshot.id })
} else {
console.error('Cannot get project', id)
}
if(project) {
let contentSnapshot = await bunkoFS.collection('projects').doc(id).collection('versions').orderBy('date', 'desc').limit(1).get()
if(contentSnapshot) {
contentSnapshot.forEach(docInSnapshot => {
let version = docInSnapshot.data()
project.contentUpdatedAt = version.date
if(withContent) {
project.content = version.content
}
})
}
}
if(project) {
project.imageObj = parseReference(project.image)
project.referenceObj = parseReference(project.reference)
}
return project
}

Expand Down Expand Up @@ -974,6 +990,23 @@ async function updateProject(projectID, project) {
return getProject(projectID)
}

async function updateProjectContent(projectID, content) {
let date = new Date()
let ref = bunkoFS.collection('projects').doc(projectID)
let docUpdate = {}
if(content.title) {
docUpdate.title = content.title
} else {
console.error('Content title not found')
}
await ref.collection('versions').add({
date,
content
})
await ref.update(Object.assign(docUpdate, getContentUpdateInfo(date)))
return getDoc(projectID, true)
}

async function getNewsletters({ limit = -1 } = {}) {
let fsRef = bunkoFS.collection('newsletters').orderBy('publishedAt', 'desc')
if(limit > 0) {
Expand Down Expand Up @@ -1096,6 +1129,7 @@ export const bunko = {
getProjectBySlug,
addProject,
updateProject,
updateProjectContent,
getNewsletters,
getNewsletter,
addNewsletter,
Expand Down
22 changes: 15 additions & 7 deletions lib/watchout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import config from '../config/config'
// }
// const compDocURLDefaultPrefix = 'docs'

export function getBaseURL(channelID, forceProductionURL = false) {
export function getBaseURL(forceProductionURL = false) {
let url = 'https://watchout.tw/'
if(!forceProductionURL) {
if(config.env === 'dev') {
Expand All @@ -26,16 +26,26 @@ export function getBaseURL(channelID, forceProductionURL = false) {
return url
}
export function getCompDocURL(publishedTo, id) {
return getBaseURL() + (publishedTo === 'musou' ? 'reports/' : 'forum/') + id
const baseURL = getBaseURL()
switch(publishedTo) {
case 'musou':
return baseURL + 'reports/' + id
case 'uc':
return baseURL + 'forum/' + id
case 'project':
return baseURL + 'projects/' + id
default:
return baseURL + 'reports/' + id
}
}

// TODO: video url is not complete
export function getCompVideoURL(publishedTo, id) {
return getBaseURL(publishedTo)
export function getCompVideoURL(id) {
return getBaseURL()
}

export function getWatchoutProjectURL(projectID, translation = null) {
return getBaseURL('watchout') + (translation ? `${translation}/` : '') + `projects/${projectID}`
return getBaseURL() + (translation ? `${translation}/` : '') + `projects/${projectID}`
}

const SEPARATOR = '://'
Expand Down Expand Up @@ -77,8 +87,6 @@ export function parseReference(content, options = {}) {
permalink = getCompVideoURL(options.publishedTo, id)
} else if(type === 'project') {
permalink = getWatchoutProjectURL(id)
} else if(type === 'channel') {
permalink = getBaseURL(id)
}

if(permalink && params) {
Expand Down

0 comments on commit 566f1b2

Please sign in to comment.