mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Finally put tag_list_cache to rest (fixes philomena-dev/philomena#128)
This commit is contained in:
parent
38c134668a
commit
66c758cb13
9 changed files with 25 additions and 13 deletions
|
@ -54,6 +54,15 @@ defmodule Philomena.Images do
|
|||
Repo.one!(Image |> where(id: ^id) |> preload(:tags))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets the tag list for a single image.
|
||||
"""
|
||||
def tag_list(%Image{tags: tags}) do
|
||||
tags
|
||||
|> Tag.display_order()
|
||||
|> Enum.map_join(", ", & &1.name)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a image.
|
||||
|
||||
|
|
|
@ -22,9 +22,7 @@ defmodule Philomena.Scrapers.Tumblr do
|
|||
[post_id] = Regex.run(@url_regex, url, capture: :all_but_first)
|
||||
|
||||
api_url =
|
||||
"https://api.tumblr.com/v2/blog/#{uri.host}/posts/photo?id=#{post_id}&api_key=#{
|
||||
tumblr_api_key()
|
||||
}"
|
||||
"https://api.tumblr.com/v2/blog/#{uri.host}/posts/photo?id=#{post_id}&api_key=#{tumblr_api_key()}"
|
||||
|
||||
Philomena.Http.get(api_url)
|
||||
|> json!()
|
||||
|
|
|
@ -95,7 +95,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
interactions: interactions,
|
||||
watching: watching,
|
||||
layout_class: "layout--wide",
|
||||
title: "##{image.id} - #{image.tag_list_cache}"
|
||||
title: "##{image.id} - #{Images.tag_list(image)}"
|
||||
]
|
||||
|
||||
if image.hidden_from_users do
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
<%= for image <- @images do %>
|
||||
<item>
|
||||
<title>#<%= image.id %> - <%= image.tag_list_cache %></title>
|
||||
<title>#<%= image.id %> - <%= tag_list(image) %></title>
|
||||
<description>
|
||||
<![CDATA[
|
||||
<% mouseovertext = "Size: #{image.image_width}x#{image.image_height} | Tagged: #{image.tag_list_cache}" %>
|
||||
<% mouseovertext = "Size: #{image.image_width}x#{image.image_height} | Tagged: #{tag_list(image)}" %>
|
||||
<a href="<%= Routes.image_url(@conn, :show, image) %>">
|
||||
<img src="<%= medium_url(image) %>" alt="<%= mouseovertext %>" title="<%= mouseovertext %>"/>
|
||||
</a>
|
||||
|
|
|
@ -5,9 +5,9 @@ meta name="format-detection" content="telephone=no"
|
|||
= if opengraph?(@conn) do
|
||||
- image = @conn.assigns.image
|
||||
- filtered = not image.thumbnails_generated
|
||||
- description = "##{image.id} - #{image.tag_list_cache} - Derpibooru"
|
||||
- description = "##{image.id} - #{Philomena.Images.tag_list(image)} - Derpibooru"
|
||||
|
||||
meta name="keywords" content=image.tag_list_cache
|
||||
meta name="keywords" content=tag_list(image)
|
||||
meta name="description" content=description
|
||||
meta property="og:title" content=description
|
||||
meta property="og:url" content=Routes.image_url(@conn, :show, image)
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule PhilomenaWeb.Api.Json.OembedView do
|
|||
%{
|
||||
version: "1.0",
|
||||
type: "photo",
|
||||
title: "##{image.id} - #{image.tag_list_cache} - Derpibooru",
|
||||
title: "##{image.id} - #{tag_list(image)} - Derpibooru",
|
||||
author_url: image.source_url || "",
|
||||
author_name: artist_tags(image.tags),
|
||||
provider_name: "Derpibooru",
|
||||
|
|
|
@ -43,6 +43,10 @@ defmodule PhilomenaWeb.AppView do
|
|||
)
|
||||
end
|
||||
|
||||
def tag_list(image) do
|
||||
Philomena.Images.tag_list(image)
|
||||
end
|
||||
|
||||
def distance_of_time_in_words(time_2, time_1) do
|
||||
seconds = abs(DateTime.diff(time_2, time_1, :second))
|
||||
minutes = div(seconds, 60)
|
||||
|
|
|
@ -58,10 +58,10 @@ defmodule PhilomenaWeb.AvatarGeneratorView do
|
|||
# 32-bit xorshift deterministic PRNG
|
||||
defp xorshift32(state) do
|
||||
state = state &&& 0xFFFF_FFFF
|
||||
state = bxor(state, (state <<< 13))
|
||||
state = bxor(state, (state >>> 17))
|
||||
state = bxor(state, state <<< 13)
|
||||
state = bxor(state, state >>> 17)
|
||||
|
||||
bxor(state, (state <<< 5))
|
||||
bxor(state, state <<< 5)
|
||||
end
|
||||
|
||||
# Generate pseudorandom, clamped RGB values with a specified
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -55,7 +55,8 @@ defmodule Philomena.MixProject do
|
|||
{:nimble_parsec, "~> 1.1"},
|
||||
{:canary, "~> 1.1"},
|
||||
{:scrivener_ecto, "~> 2.7"},
|
||||
{:pbkdf2, "~> 2.0", github: "code-time/erlang-pbkdf2", ref: "f8f0012a97f58ade9c70ac93260e4259e4ca4b8d"},
|
||||
{:pbkdf2, "~> 2.0",
|
||||
github: "code-time/erlang-pbkdf2", ref: "f8f0012a97f58ade9c70ac93260e4259e4ca4b8d"},
|
||||
{:qrcode, "~> 0.1"},
|
||||
{:redix, "~> 0.10.0"},
|
||||
{:bamboo, "~> 1.6"},
|
||||
|
|
Loading…
Reference in a new issue