drop "related items" code
We haven't been populating the database with this for some time (and any residual records have been gone for almost a year due to the database transition). And nobody seems to have noticed. Let's just give up on the feature in the name of simplicity.
This commit is contained in:
Родитель
8adc36c43f
Коммит
0529ef9c94
|
@ -150,16 +150,6 @@ header {
|
|||
}
|
||||
}
|
||||
|
||||
ul.related-material {
|
||||
font-weight: normal;
|
||||
|
||||
li {
|
||||
a {
|
||||
display: inline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation
|
||||
aside nav ul {
|
||||
margin-bottom: 1.4em;
|
||||
|
|
|
@ -123,31 +123,6 @@ ol#about-nav {
|
|||
}
|
||||
}
|
||||
|
||||
ul.related-material {
|
||||
@extend .unstyled;
|
||||
margin-bottom: 3em;
|
||||
font-size: 12px;
|
||||
|
||||
li {
|
||||
min-height: 17px;
|
||||
padding-left: 25px;
|
||||
margin-bottom: 1em;
|
||||
line-height: 1.5;
|
||||
|
||||
&.reference {
|
||||
@include background-image-2x("/images/icons/document-sm", 12px, 17px, 3px 0);
|
||||
}
|
||||
|
||||
&.book {
|
||||
@include background-image-2x("/images/icons/book-sm", 17px, 17px, 0 0);
|
||||
}
|
||||
|
||||
&.video {
|
||||
@include background-image-2x("/images/icons/film-sm", 17px, 17px, 2px 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ul.stackoverflow {
|
||||
@extend .unstyled;
|
||||
font-size: 12px;
|
||||
|
|
|
@ -37,7 +37,6 @@ class BooksController < ApplicationController
|
|||
elsif @no_edition
|
||||
return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{params[:slug]}"
|
||||
end
|
||||
@related = @content.get_related(8)
|
||||
if @content.title.blank?
|
||||
@page_title = "Git - #{@content.chapter.title}"
|
||||
else
|
||||
|
|
|
@ -23,18 +23,6 @@ class DocController < ApplicationController
|
|||
return redirect_to docs_path unless @doc_version
|
||||
@last = @doc_file.doc_versions.latest_version
|
||||
# @versions = DocVersion.version_changes(@doc_file.name)
|
||||
# @related = DocVersion.get_related(filename, 8)
|
||||
end
|
||||
|
||||
def related_update
|
||||
if params[:token] != ENV['UPDATE_TOKEN']
|
||||
return render :text => 'nope'
|
||||
end
|
||||
|
||||
fromc = params[:from_content]
|
||||
toc = params[:to_content]
|
||||
RelatedItem.create_both(fromc, toc)
|
||||
render :text => 'ok'
|
||||
end
|
||||
|
||||
# API Methods to update book content #
|
||||
|
|
|
@ -15,11 +15,6 @@ class DocVersion < ActiveRecord::Base
|
|||
delegate :name, to: :version
|
||||
delegate :committed, to: :version
|
||||
|
||||
def self.get_related(doc_name, limit = 10)
|
||||
ri = RelatedItem.where(related_type: 'reference', related_id: doc_name).order('score DESC').limit(limit)
|
||||
ri.sort_by(&:content_type)
|
||||
end
|
||||
|
||||
# returns an array of the differences with 3 entries
|
||||
# 0: additions
|
||||
# 1: subtractions
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# t.string :name
|
||||
# t.string :content_type
|
||||
# t.string :content_url
|
||||
# t.string :related_type
|
||||
# t.string :related_id
|
||||
# t.integer :score
|
||||
# t.timestamps
|
||||
class RelatedItem < ActiveRecord::Base
|
||||
|
||||
def self.create_both(from_arr, to_arr)
|
||||
ri = RelatedItem.where( :name => to_arr[1],
|
||||
:content_type => to_arr[0],
|
||||
:content_url => to_arr[3],
|
||||
:related_type => from_arr[0],
|
||||
:related_id => from_arr[2]).first_or_create
|
||||
ri.score = to_arr[4].to_i if to_arr[4].to_i > ri.score.to_i
|
||||
ri.save
|
||||
|
||||
ri = RelatedItem.where( :name => from_arr[1],
|
||||
:content_type => from_arr[0],
|
||||
:content_url => from_arr[3],
|
||||
:related_type => to_arr[0],
|
||||
:related_id => to_arr[2]).first_or_create
|
||||
ri.score = from_arr[4].to_i if from_arr[4].to_i > ri.score.to_i
|
||||
ri.save
|
||||
end
|
||||
end
|
|
@ -21,11 +21,6 @@ class Section < ActiveRecord::Base
|
|||
has_many :sections, :through => :chapter
|
||||
has_many :xrefs
|
||||
|
||||
def get_related(limit = 10)
|
||||
ri = RelatedItem.where(:related_type => 'book', :related_id => slug).order('score DESC').limit(limit)
|
||||
ri.sort { |a, b| a.content_type <=> b.content_type }
|
||||
end
|
||||
|
||||
def set_slug
|
||||
if self.title
|
||||
title = (self.chapter.title + '-' + self.title)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<% content_for :sidebar do %>
|
||||
<%= render 'translations' %>
|
||||
<%= render 'shared/related' %>
|
||||
<% end %>
|
||||
|
||||
<div id='book-chapters'>
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
<% @subsection = 'reference' %>
|
||||
|
||||
<% cache @doc do %>
|
||||
<% content_for :sidebar do %>
|
||||
<%= render 'shared/related' %>
|
||||
<% end %>
|
||||
|
||||
<div id='reference-version'>
|
||||
<%= render 'doc/topics' %>
|
||||
<%= render 'doc/versions' %>
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<% if @related && @related.size > 0 %>
|
||||
<h4>Related Material</h4>
|
||||
<ul class="related-material">
|
||||
<% @related.each do |rel| %>
|
||||
<li class="<%= rel.content_type %>">
|
||||
<strong><a href="<%= rel.content_url %>"><%= rel.name %></a></strong>
|
||||
<% if rel.content_type == "reference" %>
|
||||
in <a href="/docs">Reference</a>
|
||||
<% elsif rel.content_type == "book" %>
|
||||
in <a href="/book/en">Books</a>
|
||||
<% elsif rel.content_type == "video" %>
|
||||
in <a href="/videos">Videos</a>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
|
@ -2,10 +2,6 @@
|
|||
<% @subsection = "" %>
|
||||
<% @page_title = "Search results for #{h(@term)}" %>
|
||||
|
||||
<% content_for :sidebar do %>
|
||||
<%= render 'shared/related' %>
|
||||
<% end %>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1><%= raw "Search results for <strong>#{h(@term)}</strong>" %></h1>
|
||||
|
|
|
@ -69,7 +69,6 @@ Gitscm::Application.routes.draw do
|
|||
get "/blog" => "blog#index"
|
||||
|
||||
get "/publish" => "doc#book_update"
|
||||
post "/related" => "doc#related_update"
|
||||
|
||||
get "/about" => "about#index"
|
||||
get "/about/:section" => "about#index"
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
class AddRelated < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :related_items do |t|
|
||||
t.string :name
|
||||
t.string :content_type
|
||||
t.string :content_url
|
||||
t.string :related_type
|
||||
t.string :related_id
|
||||
t.integer :score
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :related_items
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -81,17 +81,6 @@ ActiveRecord::Schema.define(version: 20141027114732) do
|
|||
t.datetime "release_date"
|
||||
end
|
||||
|
||||
create_table "related_items", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "content_type", limit: 255
|
||||
t.string "content_url", limit: 255
|
||||
t.string "related_type", limit: 255
|
||||
t.string "related_id", limit: 255
|
||||
t.integer "score"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "sections", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.string "slug", limit: 255
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
require 'faraday'
|
||||
|
||||
# bundle exec rake related
|
||||
CONTENT_SERVER = ENV["CONTENT_SERVER"] || "http://localhost:3001"
|
||||
UPDATE_TOKEN = ENV["UPDATE_TOKEN"]
|
||||
|
||||
def http_client(url)
|
||||
@client ||= begin
|
||||
Faraday.new(url: url)
|
||||
end
|
||||
end
|
||||
|
||||
def create_related_item(from, to)
|
||||
url = CONTENT_SERVER + "/related"
|
||||
params = {
|
||||
from_content: from,
|
||||
to_content: to,
|
||||
token: UPDATE_TOKEN
|
||||
}
|
||||
http_client(url).post url, params
|
||||
end
|
||||
|
||||
desc "Generate the related sidebar content"
|
||||
task :related => :environment do
|
||||
find_reference_links
|
||||
find_book_links
|
||||
|
||||
# TODO: git-ref?
|
||||
# TODO: screencasts?
|
||||
# TODO: blog posts?
|
||||
|
||||
end
|
||||
|
||||
CMD_IGNORE = ['aware', 'binaries', 'ci', 'co', 'com', 'directory', 'feature',
|
||||
'gitolite', 'gitosis-init', 'installed', 'last', 'library', 'my',
|
||||
'mygrit', 'project', 'prune', 'rack', 'repository', 'stash-unapply',
|
||||
'tarball', 'that', 'user', 'visual', 'will', 'world', 'unstage']
|
||||
|
||||
# book content
|
||||
# - reference calls
|
||||
def find_book_links
|
||||
aindex = {}
|
||||
book = Book.where(:code => 'en', :edition => 2).first
|
||||
book.sections.each do |section|
|
||||
content = section.html
|
||||
content.scan(/git (\-+[a-z\-=]+ )*([a-z][a-z\-]+)/) do |match|
|
||||
next if CMD_IGNORE.include? match[1]
|
||||
aindex[match[1]] ||= []
|
||||
aindex[match[1]] << section.id
|
||||
end
|
||||
end
|
||||
aindex.each do |command, ids|
|
||||
command = "git-#{command}"
|
||||
sec_ids = {}
|
||||
ids.each do |id|
|
||||
sec_ids[id] ||= 0
|
||||
sec_ids[id] += 1
|
||||
end
|
||||
sec_ids.each do |id, score|
|
||||
if section = Section.find(id)
|
||||
puts "linking #{section.title} with #{command}"
|
||||
from = ['book', section.title, section.slug, "/book/en/v#{section.book.edition}/#{section.slug}", score]
|
||||
to = ['reference', command, command, "/docs/#{command}", score]
|
||||
create_related_item(from, to)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# index all reference pages
|
||||
# - linked to/from other pages
|
||||
def find_reference_links
|
||||
v = Version.latest_version
|
||||
v.doc_versions.each do |dv|
|
||||
f = dv.doc_file
|
||||
doc = dv.doc
|
||||
name = f.name
|
||||
|
||||
matches = doc.plain.scan(/linkgit:(.*?)\[(\d)\]/)
|
||||
|
||||
m = {}
|
||||
matches.each do |command, number|
|
||||
m[command] ||= 0
|
||||
m[command] += 1
|
||||
end
|
||||
related = m.sort { |a, b| b[1] <=> a[1] }[0, 5]
|
||||
|
||||
related.each do |command, score|
|
||||
next if command == name
|
||||
doc_file = DocFile.with_includes.where(name: command).limit(1).first
|
||||
rdv = doc_file.doc_versions.latest_version rescue nil
|
||||
if rdv
|
||||
puts "linking #{name} with #{command}"
|
||||
from = ['reference', name, name, "/docs/#{name}", score]
|
||||
to = ['reference', command, command, "/docs/#{command}", score]
|
||||
create_related_item(from, to)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
Fabricator(:related_item) do
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RelatedItemTest < ActiveSupport::TestCase
|
||||
|
||||
end
|
Загрузка…
Ссылка в новой задаче