Skip to content

Commit

Permalink
fix!: eliminate the x- prefix in mime-types (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Nov 21, 2024
1 parent 202751b commit 22e7d57
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.MD → CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributor Covenant Code of Conduct
# Code of Conduct

## Goal

Expand All @@ -21,7 +21,7 @@ Our standards are as follows:
Examples of unacceptable behavior include:

- Trolling, insulting or derogatory comments, and personal attacks
- Harasing or bullying another person
- Harassing or bullying another person
- Publishing others' private information without their explicit permission
- Posting things unrelated to the topic being discussed
- Other conduct that could reasonably be considered inappropriate in a professional setting
Expand Down
4 changes: 2 additions & 2 deletions yazi-config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ rules = [

# Archives
{ mime = "application/{,g}zip", fg = "red" },
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },
{ mime = "application/{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },

# Documents
{ mime = "application/{pdf,doc,rtf,vnd.*}", fg = "cyan" },

# Empty files
# { mime = "inode/x-empty", fg = "red" },
# { mime = "inode/empty", fg = "red" },

# Special files
{ name = "*", is = "orphan", bg = "red" },
Expand Down
16 changes: 8 additions & 8 deletions yazi-config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ rules = [
{ mime = "{audio,video}/*", use = [ "play", "reveal" ] },
# Archive
{ mime = "application/{,g}zip", use = [ "extract", "reveal" ] },
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", use = [ "extract", "reveal" ] },
{ mime = "application/{tar,bzip*,7z-compressed,xz,rar}", use = [ "extract", "reveal" ] },
# JSON
{ mime = "application/{json,x-ndjson}", use = [ "edit", "reveal" ] },
{ mime = "application/{json,ndjson}", use = [ "edit", "reveal" ] },
{ mime = "*/javascript", use = [ "edit", "reveal" ] },
# Empty file
{ mime = "inode/x-empty", use = [ "edit", "reveal" ] },
{ mime = "inode/empty", use = [ "edit", "reveal" ] },
# Fallback
{ name = "*", use = [ "open", "reveal" ] },
]
Expand All @@ -96,7 +96,7 @@ spotters = [
{ name = "*/", run = "folder" },
# Code
{ mime = "text/*", run = "code" },
{ mime = "*/{xml,javascript,x-wine-extension-ini}", run = "code" },
{ mime = "*/{xml,javascript,wine-extension-ini}", run = "code" },
# Image
{ mime = "image/{avif,hei?,jxl,svg+xml}", run = "magick" },
{ mime = "image/*", run = "image" },
Expand All @@ -121,9 +121,9 @@ previewers = [
{ name = "*/", run = "folder", sync = true },
# Code
{ mime = "text/*", run = "code" },
{ mime = "*/{xml,javascript,x-wine-extension-ini}", run = "code" },
{ mime = "*/{xml,javascript,wine-extension-ini}", run = "code" },
# JSON
{ mime = "application/{json,x-ndjson}", run = "json" },
{ mime = "application/{json,ndjson}", run = "json" },
# Image
{ mime = "image/{avif,hei?,jxl,svg+xml}", run = "magick" },
{ mime = "image/*", run = "image" },
Expand All @@ -133,12 +133,12 @@ previewers = [
{ mime = "application/pdf", run = "pdf" },
# Archive
{ mime = "application/{,g}zip", run = "archive" },
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar,iso9660-image}", run = "archive" },
{ mime = "application/{tar,bzip*,7z-compressed,xz,rar,iso9660-image}", run = "archive" },
# Font
{ mime = "font/*", run = "font" },
{ mime = "application/vnd.ms-opentype", run = "font" },
# Empty file
{ mime = "inode/x-empty", run = "empty" },
{ mime = "inode/empty", run = "empty" },
# Fallback
{ name = "*", run = "file" },
]
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ function M:seek(units)
})
end

function M:spot(args) require("file"):spot(args) end
function M:spot(job) require("file"):spot(job) end

return M
6 changes: 3 additions & 3 deletions yazi-plugin/preset/plugins/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ local hovered_mime = ya.sync(function()
end
end)

function M:spot(args)
function M:spot(job)
local mime = hovered_mime()
if not mime then
return
end

local file = args.file
local file = job.file
local spotter = PLUGIN.spotter(file.url, mime)
local previewer = PLUGIN.previewer(file.url, mime)
local fetchers = PLUGIN.fetchers(file.url, mime)
Expand Down Expand Up @@ -64,7 +64,7 @@ function M:spot(args)
row(" Preloaders:", #preloaders ~= 0 and preloaders or "-")

ya.spot_table(
args,
job,
ui.Table(rows)
:area(ui.Pos { "center", w = 60, h = 20 })
:row(1)
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ function M:seek(units)
end
end

function M:spot(args) require("file"):spot(args) end
function M:spot(job) require("file"):spot(job) end

return M
8 changes: 4 additions & 4 deletions yazi-plugin/preset/plugins/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function M:preload()
return ya.image_precache(self.file.url, cache) and 1 or 2
end

function M:spot(args)
local info = ya.image_info(args.file.url)
function M:spot(job)
local info = ya.image_info(job.file.url)

local rows = {}
local row = function(key, value)
Expand All @@ -37,10 +37,10 @@ function M:spot(args)
row("Color:", tostring(info.color))

ya.spot_table(
args,
job,
ui.Table(rows)
:area(ui.Pos { "center", w = 60, h = 20 })
:row(args.skip)
:row(job.skip)
:col(1)
:col_style(ui.Style():fg("blue"))
:cell_style(ui.Style():fg("yellow"):reverse())
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/magick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ function M:preload()
return status and status.success and 1 or 2
end

function M:spot(args) require("file"):spot(args) end
function M:spot(job) require("file"):spot(job) end

return M
14 changes: 6 additions & 8 deletions yazi-plugin/preset/plugins/mime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ local SUPPORTED_TYPES = "application/audio/biosig/chemical/font/image/inode/mess
local M = {}

local function match_mimetype(s)
local type, sub = s:match("([-a-z]+/)([+-.a-zA-Z0-9]+)%s*$")
if type and sub and SUPPORTED_TYPES:find(type, 1, true) then
return type .. sub
local type, sub = s:match("^([-a-z]+/)([+-.a-zA-Z0-9]+)%s*$")
if type and sub and SUPPORTED_TYPES:find(type, 1, true) then
return type:gsub("^x%-", "", 1) .. sub:gsub("^x%-", "", 1)
end
end

function M:fetch(args)
function M:fetch(job)
local urls = {}
for _, file in ipairs(args.files) do
for _, file in ipairs(job.files) do
urls[#urls + 1] = tostring(file.url)
end

Expand Down Expand Up @@ -44,9 +44,7 @@ function M:fetch(args)
end

valid = match_mimetype(line)
if valid and line:find(valid, 1, true) ~= 1 then
goto continue
elseif valid then
if valid then
j, updates[urls[i]] = j + 1, valid
flush(false)
end
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/preset/plugins/video.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ function M:preload()
return status and status.success and 1 or 2
end

function M:spot(args) require("file"):spot(args) end
function M:spot(job) require("file"):spot(job) end

return M

0 comments on commit 22e7d57

Please sign in to comment.