mirror of
https://github.com/Neetpone/foalfetch.git
synced 2025-03-11 14:10:07 +01:00
feat: markdown parsing and some other stuff
This commit is contained in:
parent
563aa6a0f8
commit
96ec959166
9 changed files with 44 additions and 10 deletions
1
Gemfile
1
Gemfile
|
@ -9,6 +9,7 @@ gem "pg", "~> 1.1"
|
||||||
gem "puma", "~> 5.0"
|
gem "puma", "~> 5.0"
|
||||||
gem 'slim-rails'
|
gem 'slim-rails'
|
||||||
gem 'kaminari'
|
gem 'kaminari'
|
||||||
|
gem 'redcarpet'
|
||||||
|
|
||||||
gem 'redis'
|
gem 'redis'
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,7 @@ GEM
|
||||||
rake (13.1.0)
|
rake (13.1.0)
|
||||||
rdoc (6.6.3.1)
|
rdoc (6.6.3.1)
|
||||||
psych (>= 4.0.0)
|
psych (>= 4.0.0)
|
||||||
|
redcarpet (3.6.0)
|
||||||
redis (5.1.0)
|
redis (5.1.0)
|
||||||
redis-client (>= 0.17.0)
|
redis-client (>= 0.17.0)
|
||||||
redis-client (0.21.1)
|
redis-client (0.21.1)
|
||||||
|
@ -276,6 +277,7 @@ DEPENDENCIES
|
||||||
pg (~> 1.1)
|
pg (~> 1.1)
|
||||||
puma (~> 5.0)
|
puma (~> 5.0)
|
||||||
rails (~> 7.0.8, >= 7.0.8.1)
|
rails (~> 7.0.8, >= 7.0.8.1)
|
||||||
|
redcarpet
|
||||||
redis
|
redis
|
||||||
selenium-webdriver
|
selenium-webdriver
|
||||||
sidekiq
|
sidekiq
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
# FoalFetch
|
# FoalFetch
|
||||||
A replacement for FiMFetch.
|
A replacement for FiMFetch.
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
|
require 'redcarpet'
|
||||||
|
|
||||||
class ChaptersController < ApplicationController
|
class ChaptersController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@story = Story.find(params[:story_id])
|
@story = Story.find(params[:story_id])
|
||||||
@chapter = @story.chapters.find_by(number: params[:id])
|
@chapter = @story.chapters.find_by(number: params[:id])
|
||||||
|
|
||||||
|
@rendered_html = markdown.render(@chapter.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def markdown
|
||||||
|
@@markdown ||=
|
||||||
|
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
|
||||||
|
# Handles proxying images from the FiMFiction CDN and caching them locally, in case they disappear.
|
||||||
class ImagesController < ApplicationController
|
class ImagesController < ApplicationController
|
||||||
|
#noinspection RubyMismatchedArgumentType
|
||||||
def show
|
def show
|
||||||
url = params[:url]
|
url = params[:url]
|
||||||
parsed = URI.parse(url)
|
parsed = URI.parse(url)
|
||||||
|
@ -10,9 +12,10 @@ class ImagesController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ext = File.extname(url)
|
||||||
hash = Digest::SHA256.hexdigest(url)
|
hash = Digest::SHA256.hexdigest(url)
|
||||||
path = Rails.root.join('public', 'cached-images', hash + File.extname(url))
|
path = Rails.root.join('public', 'cached-images', hash + ext)
|
||||||
our_url = '/cached-images/' + hash + File.extname(url)
|
our_url = '/cached-images/' + hash + ext
|
||||||
|
|
||||||
if File.exist? path
|
if File.exist? path
|
||||||
redirect_to our_url
|
redirect_to our_url
|
||||||
|
|
18
app/jobs/recount_words_job.rb
Normal file
18
app/jobs/recount_words_job.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class RecountWordsJob < ApplicationJob
|
||||||
|
def perform(*)
|
||||||
|
Story.find_each do |story|
|
||||||
|
word_count = 0
|
||||||
|
story.chapters.each do |chapter|
|
||||||
|
count = chapter.body.split(' ').size
|
||||||
|
chapter.update_columns(
|
||||||
|
num_words: count
|
||||||
|
)
|
||||||
|
word_count += count
|
||||||
|
end
|
||||||
|
|
||||||
|
story.update_columns(
|
||||||
|
num_words: word_count
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -21,9 +21,8 @@ body.story
|
||||||
- if @chapter.number < @story.chapters.count
|
- if @chapter.number < @story.chapters.count
|
||||||
= link_to 'Next Chapter', story_chapter_path(@story, @chapter.number + 1)
|
= link_to 'Next Chapter', story_chapter_path(@story, @chapter.number + 1)
|
||||||
hr
|
hr
|
||||||
== @chapter.body
|
== @rendered_html
|
||||||
|
|
||||||
span.chapnav.bot
|
span.chapnav.bot
|
||||||
- if @chapter.number < @story.chapters.count
|
- if @chapter.number < @story.chapters.count
|
||||||
= link_to 'Next Chapter', story_chapter_path(@story, @chapter.number + 1)
|
= link_to 'Next Chapter', story_chapter_path(@story, @chapter.number + 1)
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
.main
|
.main
|
||||||
#wrap
|
#wrap
|
||||||
nav.home
|
nav.home
|
||||||
= link_to "Daily Fictions", "/ficoftheday"
|
/= link_to "Daily Fictions", "/ficoftheday"
|
||||||
= link_to "News", "/news"
|
= link_to "News", "/news"
|
||||||
= link_to "About", "/about"
|
= link_to "About", "/about"
|
||||||
section.search.search-l
|
section.search.search-l
|
||||||
img alt="FoalFetch" src="/img/banner.png"
|
= image_tag '/img/banner.png', alt: 'FoalFetch'
|
||||||
= form_tag "/search", method: :post
|
= form_tag "/search", method: :post
|
||||||
.searchbox
|
.searchbox
|
||||||
= search_field_tag "q", nil, placeholder: 'Search story titles...'
|
= search_field_tag "q", nil, placeholder: 'Search story titles...'
|
||||||
= render partial: 'advanced', locals: { show_button: false }
|
= render partial: 'advanced', locals: { show_button: false }
|
||||||
.buttons
|
.buttons
|
||||||
= submit_tag 'Go Fetch!', name: 'search'
|
= submit_tag 'Go Fetch!', name: 'search'
|
||||||
= submit_tag 'Pick one for me!', name: 'luck'
|
= submit_tag 'Pick one for me!', name: 'luck'
|
||||||
|
|
|
@ -6,7 +6,8 @@ Rails.application.routes.draw do
|
||||||
get '/images' => 'images#show'
|
get '/images' => 'images#show'
|
||||||
|
|
||||||
resources :authors, only: [:show]
|
resources :authors, only: [:show]
|
||||||
resources :stories, only: [:show] do
|
# using singular-named routes to match FiMFetch/FiMFiction.
|
||||||
resources :chapters, only: [:show]
|
resources :stories, only: [:show], path: :story do
|
||||||
|
resources :chapters, only: [:show], path: :chapter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue