Repository navigation
Ads: they come with the welcome pages' lists, not every page #429
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { withPluginApi } from "discourse/lib/plugin-api"; | ||
| import type { | ||
| default as JtLinesService, | ||
| JtLines, | ||
| } from "../services/jt-lines.ts"; | ||
|
|
||
| interface ListResult { | ||
| topic_list?: { jt_lines?: JtLines | null } | null; | ||
| category_list?: { jt_lines?: JtLines | null } | null; | ||
| } | ||
|
|
||
| // The lines come inside the welcome pages' own lists (sub_plugins/ads.rb): | ||
| // Latest's topic list, the Categories page's category list. Every way core | ||
| // turns such a response into a list passes through one of these two, before | ||
| // the page renders, so the welcome area has them as it draws. | ||
| export default { | ||
| name: "jt-l-lists", | ||
|
|
||
| initialize() { | ||
| withPluginApi((api) => { | ||
| const lines = api.container.lookup("service:jt-lines") as JtLinesService; | ||
|
|
||
| api.registerValueTransformer( | ||
| "topic-list-topics-from", | ||
| ({ | ||
| value, | ||
| context, | ||
| }: { | ||
| value: unknown; | ||
| context: { result?: ListResult }; | ||
| }) => { | ||
| lines.take(context.result?.topic_list?.jt_lines); | ||
| return value; | ||
| } | ||
| ); | ||
|
|
||
| api.registerValueTransformer( | ||
| "category-list-attributes", | ||
| ({ | ||
| value, | ||
| context, | ||
| }: { | ||
| value: unknown; | ||
| context: { result?: ListResult }; | ||
| }) => { | ||
| lines.take(context.result?.category_list?.jt_lines); | ||
| return value; | ||
| } | ||
| ); | ||
| }); | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,20 @@ def key_for(name) | |
| end | ||
|
|
||
| # What the site serializer sends. Short, neutral keys on purpose. | ||
| # The lists the welcome area's pages are built from (lib/jt-lines-route | ||
| # in the browser): Latest (also the homepage, and the Categories page's | ||
| # topics) or Top (Categories with top topics), outside a category or tag | ||
| def welcome_list?(topic_list) | ||
| %w[latest top].include?(topic_list.filter.to_s) && topic_list.category.blank? && | ||
| topic_list.tags.blank? | ||
|
Comment on lines
+132
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When AGENTS.md reference: AGENTS.md:L19-L19 Useful? React with 👍 / 👎. |
||
| end | ||
|
|
||
| # The Categories page's own list, not a category's subcategories | ||
| def welcome_categories?(category_list) | ||
| options = category_list.instance_variable_get(:@options) || {} | ||
| options[:parent_category_id].blank? | ||
| end | ||
|
|
||
| def payload(guardian) | ||
| ads = visible_to(guardian) | ||
| user = guardian&.user | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,23 @@ | |
| register_svg_icon "thumbs-down" | ||
|
|
||
| after_initialize do | ||
| # Inside the page's preloaded site data: no request of the ads' own | ||
| add_to_serializer(:site, :jt_lines, include_condition: -> { DiscourseJtechAds.enabled? }) do | ||
| DiscourseJtechAds.payload(scope) | ||
| end | ||
| # Inside the welcome pages' own lists (the unscoped Latest topic list, the | ||
| # top-level category list): no request of the ads' own for a blocker to | ||
| # drop, and nothing on the pages that don't show them (topic pages are | ||
| # most of the traffic). In the site data, every page carried them. | ||
| add_to_serializer( | ||
| :topic_list, | ||
| :jt_lines, | ||
| include_condition: -> { DiscourseJtechAds.enabled? && DiscourseJtechAds.welcome_list?(object) }, | ||
| ) { DiscourseJtechAds.payload(scope) } | ||
|
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For Useful? React with 👍 / 👎. |
||
|
|
||
| add_to_serializer( | ||
| :category_list, | ||
| :jt_lines, | ||
| include_condition: -> do | ||
| DiscourseJtechAds.enabled? && DiscourseJtechAds.welcome_categories?(object) | ||
| end, | ||
| ) { DiscourseJtechAds.payload(scope) } | ||
|
|
||
| # Visitors' site data is cached; a changed ad reaches them right away | ||
| on(:site_setting_changed) do |name, _old, _new| | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
ad-remover-check.ymlworkflow, this branch treats every nonzerogit cloneresult as proof that the repository is no longer public. DNS, TLS, rate-limit, disk, or runner-network failures therefore setfound=false, skip every verification step, and leave the scheduled job green, potentially disabling the monitor indefinitely without an alert. Only the expected repository-unavailable case should be suppressed; unexpected clone failures should still fail the job.Useful? React with 👍 / 👎.