From 2835500c6200dcee28f4cfdf0035e3843c31c563 Mon Sep 17 00:00:00 2001 From: Justin DiRose Date: Tue, 16 Feb 2021 15:09:45 -0600 Subject: [PATCH] FEATURE: Make Docs compatible with inline oneboxes (#33) Linking directly to a Docs item like so `http://localhost:3000/docs?topic=16` would result in a generic inline onebox link. This adds logic to the Rails view so a proper title is rendered when the `InlineOneboxer` in core queries the route. --- app/controllers/docs/docs_controller.rb | 10 ++++++++++ app/views/docs/docs/get_topic.html.erb | 2 ++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/docs/docs_controller.rb b/app/controllers/docs/docs_controller.rb index 4575621..33b588a 100644 --- a/app/controllers/docs/docs_controller.rb +++ b/app/controllers/docs/docs_controller.rb @@ -35,6 +35,7 @@ module Docs respond_to do |format| format.html do + @title = set_title render :get_topic end @@ -53,6 +54,15 @@ module Docs TopicViewSerializer.new(topic_view, scope: guardian, root: false) end + def set_title + title = "#{I18n.t('js.docs.title')} - #{SiteSetting.title}" + if @topic + topic_title = @topic['unicode_title'] || @topic['title'] + title = "#{topic_title} - #{title}" + end + title + end + def topic_in_docs(category, tags) category_match = Docs::Query.categories.include?(category.to_s) tags = tags.pluck(:name) diff --git a/app/views/docs/docs/get_topic.html.erb b/app/views/docs/docs/get_topic.html.erb index cc248bf..c545ded 100644 --- a/app/views/docs/docs/get_topic.html.erb +++ b/app/views/docs/docs/get_topic.html.erb @@ -1,3 +1,5 @@ <% content_for :head do %> <%= raw crawlable_meta_data(title: @topic["title"], description: @excerpt, ignore_canonical: true) if @topic %> <% end %> + +<% content_for(:title) { @title } %>