Skip to content

Commit 284caa9

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Refactor image diff (go-gitea#31444) [skip ci] Updated translations via Crowdin Support relative paths to videos from Wiki pages (go-gitea#31061) Fix deprecated Dockerfile ENV format (go-gitea#31450) README Badge maintenance (go-gitea#31441) Improve markdown textarea for indentation and lists (go-gitea#31406) Split common-global.js into separate files (go-gitea#31438)
2 parents 8494ade + 1a811c0 commit 284caa9

24 files changed

+910
-726
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
FROM docker.io/library/golang:1.22-alpine3.20 AS build-env
33

44
ARG GOPROXY
5-
ENV GOPROXY ${GOPROXY:-direct}
5+
ENV GOPROXY=${GOPROXY:-direct}
66

77
ARG GITEA_VERSION
88
ARG TAGS="sqlite sqlite_unlock_notify"
9-
ENV TAGS "bindata timetzdata $TAGS"
9+
ENV TAGS="bindata timetzdata $TAGS"
1010
ARG CGO_EXTRA_CFLAGS
1111

1212
# Build deps
@@ -72,8 +72,8 @@ RUN addgroup \
7272
git && \
7373
echo "git:*" | chpasswd -e
7474

75-
ENV USER git
76-
ENV GITEA_CUSTOM /data/gitea
75+
ENV USER=git
76+
ENV GITEA_CUSTOM=/data/gitea
7777

7878
VOLUME ["/data"]
7979

Dockerfile.rootless

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
FROM docker.io/library/golang:1.22-alpine3.20 AS build-env
33

44
ARG GOPROXY
5-
ENV GOPROXY ${GOPROXY:-direct}
5+
ENV GOPROXY=${GOPROXY:-direct}
66

77
ARG GITEA_VERSION
88
ARG TAGS="sqlite sqlite_unlock_notify"
9-
ENV TAGS "bindata timetzdata $TAGS"
9+
ENV TAGS="bindata timetzdata $TAGS"
1010
ARG CGO_EXTRA_CFLAGS
1111

1212
#Build deps
@@ -75,14 +75,14 @@ COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_au
7575

7676
# git:git
7777
USER 1000:1000
78-
ENV GITEA_WORK_DIR /var/lib/gitea
79-
ENV GITEA_CUSTOM /var/lib/gitea/custom
80-
ENV GITEA_TEMP /tmp/gitea
81-
ENV TMPDIR /tmp/gitea
78+
ENV GITEA_WORK_DIR=/var/lib/gitea
79+
ENV GITEA_CUSTOM=/var/lib/gitea/custom
80+
ENV GITEA_TEMP=/tmp/gitea
81+
ENV TMPDIR=/tmp/gitea
8282

8383
# TODO add to docs the ability to define the ini to load (useful to test and revert a config)
84-
ENV GITEA_APP_INI /etc/gitea/app.ini
85-
ENV HOME "/var/lib/gitea/git"
84+
ENV GITEA_APP_INI=/etc/gitea/app.ini
85+
ENV HOME="/var/lib/gitea/git"
8686
VOLUME ["/var/lib/gitea", "/etc/gitea"]
8787
WORKDIR /var/lib/gitea
8888

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
[![](https://www.codetriage.com/go-gitea/gitea/badges/users.svg)](https://www.codetriage.com/go-gitea/gitea "Help Contribute to Open Source")
99
[![](https://opencollective.com/gitea/tiers/backers/badge.svg?label=backers&color=brightgreen)](https://opencollective.com/gitea "Become a backer/sponsor of gitea")
1010
[![](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT "License: MIT")
11-
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/go-gitea/gitea)
11+
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod&color=green)](https://gitpod.io/#https://github.com/go-gitea/gitea)
1212
[![](https://badges.crowdin.net/gitea/localized.svg)](https://crowdin.com/project/gitea "Crowdin")
13-
[![](https://badgen.net/https/api.tickgit.com/badgen/github.com/go-gitea/gitea/main)](https://www.tickgit.com/browse?repo=github.com/go-gitea/gitea&branch=main "TODOs")
1413

1514
[View this document in Chinese](./README_ZH.md)
1615

README_ZH.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
[![](https://www.codetriage.com/go-gitea/gitea/badges/users.svg)](https://www.codetriage.com/go-gitea/gitea "Help Contribute to Open Source")
99
[![](https://opencollective.com/gitea/tiers/backers/badge.svg?label=backers&color=brightgreen)](https://opencollective.com/gitea "Become a backer/sponsor of gitea")
1010
[![](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT "License: MIT")
11-
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/go-gitea/gitea)
11+
[![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod&color=green)](https://gitpod.io/#https://github.com/go-gitea/gitea)
1212
[![](https://badges.crowdin.net/gitea/localized.svg)](https://crowdin.com/project/gitea "Crowdin")
13-
[![](https://badgen.net/https/api.tickgit.com/badgen/github.com/go-gitea/gitea/main)](https://www.tickgit.com/browse?repo=github.com/go-gitea/gitea&branch=main "TODOs")
1413

1514
[View this document in English](./README.md)
1615

modules/markup/html.go

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func IsFullURLString(link string) bool {
8888
return fullURLPattern.MatchString(link)
8989
}
9090

91+
func IsNonEmptyRelativePath(link string) bool {
92+
return link != "" && !IsFullURLString(link) && link[0] != '/' && link[0] != '?' && link[0] != '#'
93+
}
94+
9195
// regexp for full links to issues/pulls
9296
var issueFullPattern *regexp.Regexp
9397

@@ -358,41 +362,6 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
358362
return nil
359363
}
360364

361-
func handleNodeImg(ctx *RenderContext, img *html.Node) {
362-
for i, attr := range img.Attr {
363-
if attr.Key != "src" {
364-
continue
365-
}
366-
367-
if attr.Val != "" && !IsFullURLString(attr.Val) && !strings.HasPrefix(attr.Val, "/") {
368-
attr.Val = util.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), attr.Val)
369-
370-
// By default, the "<img>" tag should also be clickable,
371-
// because frontend use `<img>` to paste the re-scaled image into the markdown,
372-
// so it must match the default markdown image behavior.
373-
hasParentAnchor := false
374-
for p := img.Parent; p != nil; p = p.Parent {
375-
if hasParentAnchor = p.Type == html.ElementNode && p.Data == "a"; hasParentAnchor {
376-
break
377-
}
378-
}
379-
if !hasParentAnchor {
380-
imgA := &html.Node{Type: html.ElementNode, Data: "a", Attr: []html.Attribute{
381-
{Key: "href", Val: attr.Val},
382-
{Key: "target", Val: "_blank"},
383-
}}
384-
parent := img.Parent
385-
imgNext := img.NextSibling
386-
parent.RemoveChild(img)
387-
parent.InsertBefore(imgA, imgNext)
388-
imgA.AppendChild(img)
389-
}
390-
}
391-
attr.Val = camoHandleLink(attr.Val)
392-
img.Attr[i] = attr
393-
}
394-
}
395-
396365
func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Node {
397366
// Add user-content- to IDs and "#" links if they don't already have them
398367
for idx, attr := range node.Attr {
@@ -412,20 +381,20 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Nod
412381
}
413382
}
414383

415-
// We ignore code and pre.
416384
switch node.Type {
417385
case html.TextNode:
418386
processTextNodes(ctx, procs, node)
419387
case html.ElementNode:
420-
if node.Data == "img" {
421-
next := node.NextSibling
422-
handleNodeImg(ctx, node)
423-
return next
388+
if node.Data == "code" || node.Data == "pre" {
389+
// ignore code and pre nodes
390+
return node.NextSibling
391+
} else if node.Data == "img" {
392+
return visitNodeImg(ctx, node)
393+
} else if node.Data == "video" {
394+
return visitNodeVideo(ctx, node)
424395
} else if node.Data == "a" {
425396
// Restrict text in links to emojis
426397
procs = emojiProcessors
427-
} else if node.Data == "code" || node.Data == "pre" {
428-
return node.NextSibling
429398
} else if node.Data == "i" {
430399
for _, attr := range node.Attr {
431400
if attr.Key != "class" {

modules/markup/html_node.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package markup
5+
6+
import (
7+
"code.gitea.io/gitea/modules/util"
8+
9+
"golang.org/x/net/html"
10+
)
11+
12+
func visitNodeImg(ctx *RenderContext, img *html.Node) (next *html.Node) {
13+
next = img.NextSibling
14+
for i, attr := range img.Attr {
15+
if attr.Key != "src" {
16+
continue
17+
}
18+
19+
if IsNonEmptyRelativePath(attr.Val) {
20+
attr.Val = util.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), attr.Val)
21+
22+
// By default, the "<img>" tag should also be clickable,
23+
// because frontend use `<img>` to paste the re-scaled image into the markdown,
24+
// so it must match the default markdown image behavior.
25+
hasParentAnchor := false
26+
for p := img.Parent; p != nil; p = p.Parent {
27+
if hasParentAnchor = p.Type == html.ElementNode && p.Data == "a"; hasParentAnchor {
28+
break
29+
}
30+
}
31+
if !hasParentAnchor {
32+
imgA := &html.Node{Type: html.ElementNode, Data: "a", Attr: []html.Attribute{
33+
{Key: "href", Val: attr.Val},
34+
{Key: "target", Val: "_blank"},
35+
}}
36+
parent := img.Parent
37+
imgNext := img.NextSibling
38+
parent.RemoveChild(img)
39+
parent.InsertBefore(imgA, imgNext)
40+
imgA.AppendChild(img)
41+
}
42+
}
43+
attr.Val = camoHandleLink(attr.Val)
44+
img.Attr[i] = attr
45+
}
46+
return next
47+
}
48+
49+
func visitNodeVideo(ctx *RenderContext, node *html.Node) (next *html.Node) {
50+
next = node.NextSibling
51+
for i, attr := range node.Attr {
52+
if attr.Key != "src" {
53+
continue
54+
}
55+
if IsNonEmptyRelativePath(attr.Val) {
56+
attr.Val = util.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), attr.Val)
57+
}
58+
attr.Val = camoHandleLink(attr.Val)
59+
node.Attr[i] = attr
60+
}
61+
return next
62+
}

modules/markup/html_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func TestRender_ShortLinks(t *testing.T) {
522522
`<p><a href="https://example.org" rel="nofollow">[[foobar]]</a></p>`)
523523
}
524524

525-
func TestRender_RelativeImages(t *testing.T) {
525+
func TestRender_RelativeMedias(t *testing.T) {
526526
render := func(input string, isWiki bool, links markup.Links) string {
527527
buffer, err := markdown.RenderString(&markup.RenderContext{
528528
Ctx: git.DefaultContext,
@@ -548,6 +548,15 @@ func TestRender_RelativeImages(t *testing.T) {
548548

549549
out = render(`<img src="/LINK">`, true, markup.Links{Base: "/test-owner/test-repo", BranchPath: "test-branch"})
550550
assert.Equal(t, `<img src="/LINK"/>`, out)
551+
552+
out = render(`<video src="LINK">`, false, markup.Links{Base: "/test-owner/test-repo"})
553+
assert.Equal(t, `<video src="/test-owner/test-repo/LINK"></video>`, out)
554+
555+
out = render(`<video src="LINK">`, true, markup.Links{Base: "/test-owner/test-repo"})
556+
assert.Equal(t, `<video src="/test-owner/test-repo/wiki/raw/LINK"></video>`, out)
557+
558+
out = render(`<video src="/LINK">`, false, markup.Links{Base: "/test-owner/test-repo"})
559+
assert.Equal(t, `<video src="/LINK"></video>`, out)
551560
}
552561

553562
func Test_ParseClusterFuzz(t *testing.T) {

options/locale/locale_fr-FR.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ remove_all=Tout Retirer
9393
remove_label_str=Supprimer l’élément « %s »
9494
edit=Éditer
9595
view=Voir
96+
test=Test
9697
9798
enabled=Activé
9899
disabled=Désactivé
@@ -1238,6 +1239,7 @@ file_view_rendered=Voir le rendu
12381239
file_view_raw=Voir le Raw
12391240
file_permalink=Lien permanent
12401241
file_too_large=Le fichier est trop gros pour être affiché.
1242+
file_is_empty=Le fichier est vide.
12411243
code_preview_line_from_to=Lignes %[1]d à %[2]d dans %[3]s
12421244
code_preview_line_in=Ligne %[1]d dans %[2]s
12431245
invisible_runes_header=`Ce fichier contient des caractères Unicode invisibles.`
@@ -3223,6 +3225,10 @@ config.cache_adapter=Adaptateur du Cache
32233225
config.cache_interval=Intervales du Cache
32243226
config.cache_conn=Liaison du Cache
32253227
config.cache_item_ttl=Durée de vie des éléments dans le cache
3228+
config.cache_test=Test du cache
3229+
config.cache_test_failed=Impossible d’interroger le cache : %v.
3230+
config.cache_test_slow=Test du cache réussi, mais la réponse est lente : %s.
3231+
config.cache_test_succeeded=Test du cache réussi, réponse obtenue en %s.
32263232
32273233
config.session_config=Configuration de session
32283234
config.session_provider=Fournisseur de session

templates/repo/diff/image_diff.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
data-mime-before="{{.sniffedTypeBase.GetMimeType}}"
88
data-mime-after="{{.sniffedTypeHead.GetMimeType}}"
99
>
10-
<overflow-menu class="ui secondary pointing tabular top attached borderless menu">
10+
<overflow-menu class="ui secondary pointing tabular menu custom">
1111
<div class="overflow-menu-items tw-justify-center">
1212
<a class="item active" data-tab="diff-side-by-side-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.side_by_side"}}</a>
1313
{{if and .blobBase .blobHead}}

web_src/js/features/admin/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import {checkAppUrl} from '../common-global.js';
2+
import {checkAppUrl} from '../common-page.js';
33
import {hideElem, showElem, toggleElem} from '../../utils/dom.js';
44
import {POST} from '../../modules/fetch.js';
55

0 commit comments

Comments
 (0)