Skip to content

Commit

Permalink
Switched to serving publications from distinct sources (#684)
Browse files Browse the repository at this point in the history
* Bumping project to next minor version

* Rendering publications from distinct sources by default from now on + clean up

* Removing link responsible for toggling distinct sources view
  • Loading branch information
revue-de-presse authored Jul 14, 2023
1 parent 710234d commit f506b16
Show file tree
Hide file tree
Showing 9 changed files with 20,599 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.14.0
18.16.1
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.14.2
nodejs 18.16.1
6 changes: 0 additions & 6 deletions components/calendar-month/calendar-month.vue
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,6 @@ class CalendarMonth extends mixins(ApiMixin) {
canonicalUrl (date: Date) {
const day = Time.formatDate(date)
if (day === Time.formatDate(this.now())) {
if (!this.showingDistinctSources) {
return `${Site.baseURL}`
}
}
return `${Site.baseURL}/${day}${this.localizeDatePath(day)}`
}
Expand Down
9 changes: 0 additions & 9 deletions components/outro/outro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<p :class="firstParagraphClasses">
Retrouver chaque jour les 10 tweets médias
ayant été les plus relayés au cours de la journée.<br /><br />
<a :href="switchBetweenFilteringModes" v-text="filterLabel" /><br /><br />
<span
v-if="showSubscribeToTwitterAccountButton"
class="outro__subscribe-to"
Expand Down Expand Up @@ -117,14 +116,6 @@ class Outro extends mixins(ApiMixin) {
`
}
get filterLabel () {
if (this.showingDistinctSources) {
return 'Autoriser l\'apparition d\'un même média plusieurs fois 📰'
}
return 'Empêcher qu\'un même média apparaisse plusieurs fois 🗞🗞🗞'
}
get introducingIcon () {
const width = '22px'
const height = '15px'
Expand Down
80 changes: 6 additions & 74 deletions mixins/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,16 @@ export default class ApiMixin extends DateMixin {
return routes
}

get distinctSourcesQueryParam (): string {
if (this.showingDistinctSources) {
return '?sources-distinctes'
}

return ''
}

get homepagePath () {
const today = this.formatDate(now())

if (this.distinctSourcesQueryParam) {
return `/${today}${this.localizeDatePath(today)}`
}

return '/'
}

get legalNoticePagePath (): string {
return `/mentions-legales${this.distinctSourcesQueryParam}`
return '/mentions-legales'
}

get contactPagePath (): string {
return `/nous-contacter${this.distinctSourcesQueryParam}`
return '/nous-contacter'
}

get showingContactPage () {
Expand All @@ -77,73 +63,19 @@ export default class ApiMixin extends DateMixin {
}

get supportPagePath (): string {
return `/nous-soutenir${this.distinctSourcesQueryParam}`
return '/nous-soutenir'
}

get sourcesPagePath (): string {
return `/sources${this.distinctSourcesQueryParam}`
return '/sources'
}

sourcePath (status: FormattedStatus) {
return `${sourcePath(status)}${this.distinctSourcesQueryParam}`
}

get showingDistinctSources () {
const matchingParam: string|undefined = Object.keys(this.$route.query).find(param => param === 'sources-distinctes')

return typeof matchingParam !== 'undefined' || this.$route.name === 'highlights-from-distinct-sources'
}

get switchBetweenFilteringModes () {
const path = this.$route.path
const query = structuredClone(this.$route.query)
const params = structuredClone(this.$route.params)

const pattern = '\\?[^\\?]+$'
const postSubstitutionPath = path.replace(new RegExp(pattern, 'gi'), '')

if (this.showingDistinctSources) {
delete query['sources-distinctes']

if (this.$route.name === 'highlights-from-distinct-sources') {
if (params.day === this.formatDate(this.now())) {
return this.$router.resolve({ name: 'homepage', query }).href
}

return this.$router.resolve({ name: 'curated-highlights', params, query }).href
}

return this.$router.resolve({ path: postSubstitutionPath, query }).href
}

if (this.$route.name === 'curated-highlights') {
delete query['sources-distinctes']

params.localizedDate = this.localizeDate(params.day)

return this.$router.resolve({ name: 'highlights-from-distinct-sources', params }).href
}

if (this.$route.name === 'homepage') {
delete query['sources-distinctes']

params.day = this.formatDate(this.now())
params.localizedDate = this.localizeDate(params.day)

return this.$router.resolve({ name: 'highlights-from-distinct-sources', params }).href
}

query['sources-distinctes'] = 'true'

return this.$router.resolve({ path: postSubstitutionPath, query }).href
return `${sourcePath(status)}`
}

localizeDatePath (day: string): string {
if (this.showingDistinctSources) {
return `${HIGHLIGHTS_PATH_PREFIX}${this.localizeDate(day)}`
}

return ''
return `${HIGHLIGHTS_PATH_PREFIX}${this.localizeDate(day)}`
}

localizeDate (date: string): string {
Expand Down
52 changes: 0 additions & 52 deletions mixins/status-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,60 +110,8 @@ type FormattedStatus = {
metrics?: VanityMetrics
}

type FilteringFn = (status: RawStatus) => boolean

type Filter = FilteringFn | undefined | null | 'media' | 'top100'

@Component
export default class StatusFormat extends Vue {
filterStatuses (statuses: RawStatus[], filterType: Filter) {
if (typeof filterType === 'undefined' || filterType === null) {
return statuses
}

let filteredStatuses

if (typeof filterType === 'function') {
filteredStatuses = Object.values(statuses).filter(filterType)

if (filteredStatuses.length === 0) {
throw new Errors.NoRemainingStatusAfterApplyingFilter()
}

return filteredStatuses
}

if (filterType === 'media') {
const filter = (status: RawStatus) => status.media && status.media.length > 0
filteredStatuses = Object.values(statuses).filter(filter)
if (filteredStatuses.length === 0) {
EventHub.$emit('status_list.apologize_about_empty_list_intended')
return Object.values(statuses)
}

return filteredStatuses
}

if (filterType === 'top100') {
filteredStatuses = Object.values(Object.assign({}, statuses))
const sortByRetweet = (firstStatus: RawStatus, secondStatus: RawStatus) => {
if (firstStatus.totalRetweet === secondStatus.totalRetweet) {
return 0
}

if (firstStatus.totalRetweet < secondStatus.totalRetweet) {
return 1
}

return -1
}

return filteredStatuses.sort(sortByRetweet).slice(0, 10)
}

return statuses
}

formatStatus (tweet: RawStatus) {
const formattedStatuses = this.formatStatuses([tweet])

Expand Down
Loading

0 comments on commit f506b16

Please sign in to comment.