Skip to content

Commit

Permalink
v 0.75 (See update_log.md)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiletruedoend committed Jul 3, 2021
1 parent 2289e6d commit 69c9cc4
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ gem 'image_processing'
gem 'open-uri'
gem 'pg'
gem 'rubyzip'
gem 'reverse_markdown'

gem 'sidekiq'

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ GEM
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
reverse_markdown (2.0.0)
nokogiri
rmagick (4.2.2)
rollbar (3.2.0)
rspec-core (3.10.1)
Expand Down Expand Up @@ -325,6 +327,7 @@ DEPENDENCIES
rack-mini-profiler (~> 2.0)
rails (~> 6.1.2)
redcarpet
reverse_markdown
rmagick
rollbar
rubyzip
Expand Down
14 changes: 14 additions & 0 deletions app/assets/stylesheets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ $color-black: #000000;
}
}

body#bg-clear{
background-color:$bg;
footer{
color: $font;
}
pre{
color: $font;
background-color: $bg;
border: none;
white-space: pre-wrap;
word-wrap: break-word;
}
}

table {
border-collapse: collapse;
}
Expand Down
6 changes: 3 additions & 3 deletions app/assets/stylesheets/ruby_theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "base";

$bg: #ffffff;
$bg: #f2f2f4;

$color-link-light: #bd6d76;
$color-link: #df4655;
Expand All @@ -12,7 +12,7 @@ $color-avatar-border: #1b1b1c;
$color-privacy-registered-p: #1375b2;
$color-privacy-registered: #5cb85c;
$color-privacy-me-p: #df4655;
$color-privacy-me: #4e518b;
$color-privacy-me: #5659e0;

$color-wrapper: #515151;

Expand Down Expand Up @@ -53,7 +53,7 @@ $color-code-bg: #222426;
$font: #000000;
$font-link: #b3b3b3;

$color-white: #f0f0f0;
$color-white: #fcfcff;
$color-black: #000000;

@include base($bg, $color-darkpurple, $color-code-bg,
Expand Down
3 changes: 2 additions & 1 deletion app/commands/export_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class ExportFiles

def initialize(post)
@post = post
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: false, fenced_code_blocks: false, disable_indented_code_blocks: true, autolink: false, tables: false, underline: false, highlight: false)
end

def call

title = @post.title
content_text = @post.get_content
content_text = ReverseMarkdown.convert(@markdown.render(@post.get_content), unknown_tags: :pass_through)
text = title.present? ? "## #{title}\n\n#{content_text}" : "#{content_text}"

post_dir = "tmp/export/#{@post.id.to_s}"
Expand Down
16 changes: 13 additions & 3 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class PostsController < ApplicationController

before_action :authenticate_user!, except: [:rss, :show]
before_action :check_admin, except: [:rss, :index, :show]
before_action :authenticate_user!, except: [:rss, :show, :export, :raw]
before_action :check_admin, except: [:rss, :index, :show, :export, :raw]

def check_admin
redirect_to root_path unless current_user.is_admin
Expand Down Expand Up @@ -106,7 +106,7 @@ def rss
def export
@post = Post.find_by_id(params[:id])
if @post.present?
return render file: "#{Rails.root}/public/404.html", layout: false, status: 404 if !@post.check_privacy(current_user) || (@post.user != current_user)
return render file: "#{Rails.root}/public/404.html", layout: false, status: 404 if @post.user != current_user
else
return render file: "#{Rails.root}/public/404.html", layout: false, status: 404
end
Expand All @@ -118,6 +118,16 @@ def export
send_file(file[:path], filename: file[:filename], type: file[:type])
end

def raw
@post = Post.find_by_id(params[:id])
if @post.present?
return render file: "#{Rails.root}/public/404.html", layout: false, status: 404 unless @post.check_privacy(current_user)
else
return render file: "#{Rails.root}/public/404.html", layout: false, status: 404
end
render 'posts/raw', layout: 'clear'
end

def import
if params[:file].present?
file_blob = ActiveStorage::Blob.find_signed!(params[:file])
Expand Down
9 changes: 8 additions & 1 deletion app/helpers/posts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ def display_attachments(post)
150
else
100
end
end

documents = post.get_content_attachments.select{ |b| !b.image? && !b.video? && !b.audio? }
documents.each do |att|
content += "<br><a target=\"_blank\" href=\"#{url_for(att)}\"> #{I18n.t("posts.download")} #{truncate(att.filename.to_s, length: 100)} </a>"
end if documents.any?
content += "<br><br>" if documents.any?

post.get_content_attachments&.each do |att|
case
when att.image?
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>/dev/wtde</title>
<title><%=Rails.configuration.credentials[:title]%></title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

Expand Down
15 changes: 15 additions & 0 deletions app/views/layouts/clear.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title><%=Rails.configuration.credentials[:title]%></title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "#{current_theme}", media: 'all', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<%= yield %>
</body>

</html>
4 changes: 2 additions & 2 deletions app/views/posts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<div id="attachments" class="tab-pane">
<h3><%= I18n.t("posts.current_attachments") %>:</h3>
<% if platforms.empty? || platforms.values.exclude?(true)%>
<div class="dropzone dropzone-default dz-clickable" data-controller="dropzone" data-dropzone-max-file-size="10" data-dropzone-max-files="10">
<div class="dropzone dropzone-default dz-clickable" data-controller="dropzone" data-dropzone-max-file-size="<%=Rails.configuration.credentials[:max_file_size]%>" data-dropzone-max-files="<%=Rails.configuration.credentials[:max_upload_files]%>">
<%= f.file_field :attachments, multiple: true, direct_upload: true, data: { target: 'dropzone.input' } %>
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title"><%= I18n.t("posts.attachments_msg_title") %></h3>
<span class="dropzone-msg-desc text-sm"><%= I18n.t("posts.attachments_msg_description") %></span>
<span class="dropzone-msg-desc text-sm"><%= "#{I18n.t("posts.attachments_msg_max_size")}: #{Rails.configuration.credentials[:max_file_size]} MB; #{I18n.t("posts.attachments_msg_max_count")}: #{Rails.configuration.credentials[:max_upload_files]}" %></span>
</div>
</div>
<% end %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@
<% if current_user == post.user %>
| <a href="/posts/<%=post.id%>/edit"><%= I18n.t("posts.edit_post") %></a>
| <a href="/posts/delete/<%=post.id%>" data-confirm="<%= I18n.t("posts.delete_post_confirm") %>"><%= I18n.t("posts.delete_post") %></a>
| <a href="/posts/export/<%=post.id%>"><%= I18n.t("posts.export") %></a>
<% end %>
</i>
</p>
<p class="metadata">
<i class="fa fa-gear"> <%= I18n.t("posts.options") %>: <a href="/posts/raw/<%=post.id%>"><%= I18n.t("posts.raw") %></a>
<% if current_user == post.user %>
| <a href="/posts/export/<%=post.id%>"><%= I18n.t("posts.export") %></a>
<% end %>
</i>
</p>
</header>
<%= display_attachments(post) if post.get_content_attachments.present? %>
<div class="posts-content"><% if post.get_content.length > 512 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<p id="chars" class="chars">0 chars</p>
</div>
<div id="attachments" class="tab-pane">
<div class="dropzone dropzone-default dz-clickable" data-controller="dropzone" data-dropzone-max-file-size="10" data-dropzone-max-files="10">
<div class="dropzone dropzone-default dz-clickable" data-controller="dropzone" data-dropzone-max-file-size="<%=Rails.configuration.credentials[:max_file_size]%>" data-dropzone-max-files="<%=Rails.configuration.credentials[:max_upload_files]%>">
<%= f.file_field :attachments, multiple: true, direct_upload: true, data: { target: 'dropzone.input' } %>
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title"><%= I18n.t("posts.attachments_msg_title") %></h3>
<span class="dropzone-msg-desc text-sm"><%= I18n.t("posts.attachments_msg_description") %></span>
<span class="dropzone-msg-desc text-sm"><%= "#{I18n.t("posts.attachments_msg_max_size")}: #{Rails.configuration.credentials[:max_file_size]} MB; #{I18n.t("posts.attachments_msg_max_count")}: #{Rails.configuration.credentials[:max_upload_files]}" %></span>
</div>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/views/posts/raw.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: false, fenced_code_blocks: false, disable_indented_code_blocks: true, autolink: false, tables: false, underline: false, highlight: false) %>
<body id="bg-clear">
<pre>
<%= @post.title %>

<% if @post.get_content_attachments.present? %>
<% att = display_attachments(@post) %>
<%= ReverseMarkdown.convert(@markdown.render(att), unknown_tags: :pass_through) %>
<% end %>
<%= ReverseMarkdown.convert(@markdown.render(@post.get_content), unknown_tags: :pass_through) %>
</pre>
</body>
4 changes: 2 additions & 2 deletions app/views/posts/rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ xml.instruct! :xml, :version=>"1.0"
xml.rss version: '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do

xml.channel do
xml.title 'Title'
xml.description 'Description'
xml.title "#{Rails.configuration.credentials[:title]}"
xml.description "#{Rails.configuration.credentials[:rss_description]}"
xml.link root_url
xml.language 'ru'
xml.tag! 'atom:link', rel: 'self', type: 'application/rss+xml', href: "http://#{Rails.configuration.credentials[:host]}:#{Rails.configuration.credentials[:port]}/rss?rss_token=#{(params.has_key?(:rss_token) && User.find_by_rss_token(params[:rss_token].to_s).present?) ? params[:rss_token] : (current_user&.rss_token || "none")}"
Expand Down
6 changes: 6 additions & 0 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<% if current_user == @post.user %>
| <a href="<%=@post.id%>/edit"><%= I18n.t("posts.edit_post") %></a>
| <a href="/posts/delete/<%=@post.id%>" data-confirm="<%= I18n.t("posts.delete_post_confirm") %>"><%= I18n.t("posts.delete_post") %></a>
<% end %>
</i>
</p>
<p class="metadata">
<i class="fa fa-gear"> <%= I18n.t("posts.options") %>: <a href="/posts/raw/<%=@post.id%>"><%= I18n.t("posts.raw") %></a>
<% if current_user == @post.user %>
| <a href="/posts/export/<%=@post.id%>"><%= I18n.t("posts.export") %></a>
<% end %>
</i>
Expand Down
8 changes: 8 additions & 0 deletions config/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ development:
port: 3080
locale: :en # Also supports :ru
time_zone: 'Europe/Moscow' # 'UTC'
title: Twilight # title in header
rss_description: Description
rss_default_visible_posts: 30
rss_max_visible_posts: 50
max_upload_files: 10
max_file_size: 10
invite_codes_register_only: false
rollbar:
enabled: false
Expand All @@ -25,8 +29,12 @@ production:
port: 3080
locale: :en # Also supports :ru
time_zone: 'Europe/Moscow' # 'UTC'
title: Twilight # title in header
rss_description: Description
rss_default_visible_posts: 30
rss_max_visible_posts: 50
max_upload_files: 10
max_file_size: 10
invite_codes_register_only: false
rollbar:
enabled: false
Expand Down
6 changes: 5 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ en:
all_posts: All posts
reset_filters: Reset filters
publish_date: Publish date
options: Options
profile: Profile
author: Author
download: Download
edit_post: Edit
delete_post: Delete post
delete_post_confirm: Are you sure?
Expand All @@ -43,7 +45,8 @@ en:
title_placeholder: Enter title...
text_placeholder: Enter some text...
attachments_msg_title: Drag here to upload or click here to browse
attachments_msg_description: 10 MB file size and count maximum.
attachments_msg_max_size: Max file size
attachments_msg_max_count: Max files count
channels: Channels
channels_not_found: Channels not found!
tags: Tags
Expand All @@ -58,6 +61,7 @@ en:
import: Import
import_msg: Supports only .md file format!
search_without_results: Search hasn't given any results!
raw: Raw
tags:
tags_header: New tags
name: Name
Expand Down
6 changes: 5 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ ru:
all_posts: Все посты
reset_filters: Сбросить фильтры
publish_date: Дата публикации
options: Опции
profile: Профиль
author: Автор
download: Загрузить
edit_post: Редактировать
delete_post: Удалить статью
delete_post_confirm: Вы серьёзно?
Expand All @@ -43,7 +45,8 @@ ru:
title_placeholder: Введите заголовок...
text_placeholder: Введите текст...
attachments_msg_title: Перетащите сюда некоторые файлы
attachments_msg_description: "Максимальный размер (Мб) и количество файлов: 10"
attachments_msg_max_size: Макс. размер файлов
attachments_msg_max_count: Макс. количество файлов
channels: Каналы
channels_not_found: Каналы не найдены!
tags: Тэги
Expand All @@ -58,6 +61,7 @@ ru:
import: Импорт
import_msg: Поддерживаются только .md файлы!
search_without_results: Поиск не дал результатов!
raw: Текст
tags:
tags_header: Новые тэги
name: Название
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
get '/stats/full_users_list', to: 'pages#full_users_list', as: :full_users_list
get '/manage/full_invite_codes_list', to: 'pages#full_invite_codes_list', as: :full_invite_codes_list

get 'posts/raw/:id', to: 'posts#raw', as: :raw_post_path

root to: 'pages#main'

telegram_webhook TelegramController
Expand Down
11 changes: 11 additions & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
### Format: Y-M-D

### 2021-07-03 => v0.75

* Добавлен просмотр 'Raw' текста заметки;
* Добавлена колонка 'Options' в метаданных поста:
* Raw текст и экпорт (если разрешено) перенесены туда;
* Добавлена возможность скачивать прикреплённые к посту файлы;
* Экспорт постов теперь в markdown-синтаксисе;
* Название сайта вынесено в credentials.yml;
* Изменён background у темы 'Ruby';
* Мелкие фиксы;

### 2021-06-27 => v0.7

* Добавлен поиск по заголовку заметки на (главной странице заметок);
Expand Down

0 comments on commit 69c9cc4

Please sign in to comment.