Skip to content

Commit

Permalink
Merge branch 'discourse-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshinotdead committed Aug 10, 2023
2 parents 454f324 + dc11415 commit 35082cd
Show file tree
Hide file tree
Showing 99 changed files with 4,037 additions and 1,292 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/discourse-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Discourse Plugin

on:
push:
branches:
- main
pull_request:

jobs:
ci:
uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1
57 changes: 0 additions & 57 deletions .github/workflows/plugin-linting.yml

This file was deleted.

156 changes: 0 additions & 156 deletions .github/workflows/plugin-tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
inherit_gem:
rubocop-discourse: default.yml
rubocop-discourse: stree-compat.yml
2 changes: 2 additions & 0 deletions .streerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--print-width=100
--plugins=plugin/trailing_comma
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

group :development do
gem 'rubocop-discourse'
gem "rubocop-discourse"
gem "syntax_tree"
end
37 changes: 21 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
parallel (1.20.1)
parser (3.0.1.0)
json (2.6.2)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
rainbow (3.0.0)
regexp_parser (2.1.1)
prettier_print (1.2.0)
rainbow (3.1.1)
regexp_parser (2.6.0)
rexml (3.2.5)
rubocop (1.13.0)
rubocop (1.36.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.0.0.0)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-discourse (2.4.1)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-discourse (3.0)
rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0)
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
rubocop-rspec (2.13.2)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
unicode-display_width (2.0.0)
syntax_tree (5.1.0)
prettier_print (>= 1.2.0)
unicode-display_width (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
rubocop-discourse
syntax_tree

BUNDLED WITH
2.2.16
2.3.4
33 changes: 13 additions & 20 deletions app/controllers/docs/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Docs
class DocsController < ApplicationController
requires_plugin 'docs'
requires_plugin PLUGIN_NAME

skip_before_action :check_xhr, only: [:index]

Expand All @@ -15,20 +15,23 @@ def index
search_term: params[:search],
ascending: params[:ascending],
order: params[:order],
page: params[:page]
page: params[:page],
}

query = Docs::Query.new(current_user, filters).list
query = Docs::Query.new(guardian, filters).list

if filters[:topic].present?
begin
@topic = Topic.find(filters[:topic])
rescue
rescue StandardError
raise Discourse::NotFound
end

@excerpt = @topic.posts[0].excerpt(500, { strip_links: true, text_entities: true }) if @topic.posts[0].present?
@excerpt = (@excerpt || "").gsub(/\n/, ' ').strip
@excerpt =
@topic.posts[0].excerpt(500, { strip_links: true, text_entities: true }) if @topic.posts[
0
].present?
@excerpt = (@excerpt || "").gsub(/\n/, " ").strip

query["topic"] = get_topic(@topic, current_user)
end
Expand All @@ -39,14 +42,12 @@ def index
render :get_topic
end

format.json do
render json: query
end
format.json { render json: query }
end
end

def get_topic(topic, current_user)
return nil unless topic_in_docs(topic.category_id, topic.tags)
return nil unless Docs.topic_in_docs(topic.category_id, topic.tags)

topic_view = TopicView.new(topic.id, current_user)
guardian = Guardian.new(current_user)
Expand All @@ -65,20 +66,12 @@ def should_track_visit_to_topic?
end

def set_title
title = "#{I18n.t('js.docs.title')} - #{SiteSetting.title}"
title = "#{I18n.t("js.docs.title")} - #{SiteSetting.title}"
if @topic
topic_title = @topic['unicode_title'] || @topic['title']
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)
tag_match = Docs::Query.tags.any? { |tag| tags.include?(tag) }

category_match || tag_match
end
end
end
4 changes: 0 additions & 4 deletions app/views/connectors/robots_txt_index/docs.html.erb

This file was deleted.

Loading

0 comments on commit 35082cd

Please sign in to comment.