隐藏 Mastodon 站点信息和用户嘟文列表
Mastodon 实例默认会在网页版中显示站点的用户数量和嘟文数量。此外,用户主页上会显示所有公开的嘟文。但是对于自建实例,有时候你并不想让别人可以通过网页来访问这些信息和数据。本文以 Mastodon v3.1.3 为例,通过修改代码来实现隐藏目的。本文提供的方法未在其他版本上验证,可能会不兼容。
隐藏站点用户总数和嘟文总数
Mastodon 默认会在「关于本站」页面中显示站点的用户数量和嘟文数量。通过修改代码可以隐藏这些信息。使用编辑器打开 app/views/about/more.html.haml
文件,将第 18 行至第 25 行的代码注释:
-#.information-board__section
-#%span= t 'about.user_count_before'
-#%strong= number_with_delimiter @instance_presenter.user_count
-#%span= t 'about.user_count_after', count: @instance_presenter.user_count
-#.information-board__section
-#%span= t 'about.status_count_before'
-#%strong= number_with_delimiter @instance_presenter.status_count
-#%span= t 'about.status_count_after', count: @instance_presenter.status_count
另编辑 app/views/about/show.html.haml
文件,将 68 行至 79 行的代码注释:
-#.hero-widget__footer__column
-#%h4= t 'about.server_stats'
-#%div{ style: 'display: flex' }
-#.hero-widget__counter{ style: 'width: 50%' }
-#%strong= number_to_human @instance_presenter.user_count, strip_insignificant_zeros: true
-#%span= t 'about.user_count_after', count: @instance_presenter.user_count
-#.hero-widget__counter{ style: 'width: 50%' }
-#%strong= number_to_human @instance_presenter.active_user_count, strip_insignificant_zeros: true
-#%span
-#= t 'about.active_count_after'
-#%abbr{ title: t('about.active_footnote') } *
隐藏用户主页的嘟文列表
通过网页访问用户主页,默认会显示该用户的公开嘟文列表。通过修改代码可以对未登录用户隐藏嘟文列表。使用编辑器打开 app/views/accounts/show.html.haml
文件,定位到第 32 行代码:
- if user_signed_in? && @account.blocking?(current_account)
将此行代码改为:
- if !user_signed_in? || @account.blocking?(current_account)
隐藏站点管理员
使用编辑器打开 app/views/accounts/show.html.haml
文件,将 63 行至 66 行的代码注释:
-#.hero-widget__footer__column
-#%h4= t 'about.administered_by'
-#= account_link_to @instance_presenter.contact_account
使用编辑器打开 app/views/about/more.html.haml
文件,将第 32 行至第 41 行的代码注释:
-#%h4= t 'about.administered_by'
-#= account_link_to(@instance_presenter.contact_account)
-#- if @instance_presenter.site_contact_email.present?
-#%h4
-#= succeed ':' do
-#= t 'about.contact'
-#= mail_to @instance_presenter.site_contact_email, nil, title: @instance_presenter.site_contact_email
隐藏用户公开嘟文
通过网页可以访问用户的公开嘟文。通过修改代码可以对未登录用户隐藏嘟文。使用编辑器打开 app/views/statuses/embed.html.haml
文件,新增第二行 - if user_signed_in?
判断,将内容改为:
.activity-stream.activity-stream--headless
- if user_signed_in?
= render 'status', status: @status, centered: true, autoplay: @autoplay
使用编辑器打开 app/views/statuses/show.html.haml
文件,在第 21 行和第 22 行中间加入 - if user_signed_in?
判断:
.activity-stream.h-entry
- if user_signed_in?
= render partial: 'status', locals: { status: @status, include_threads: true }
BTW,文中提及的所有改动都需要重启 Mastodon Web 进程才能生效:
bashsudo systemctl restart mastodon-web
此外,本文是通过修改网页模板来实现隐藏信息的,仅对当前站点的网页生效,对 Mastodon 的实际业务逻辑并没有影响。