Accions

Incrustar videos YouTube al wiki Recursos docents: diferència entre les revisions

De URecursos

Cap resum de modificació
Cap resum de modificació
Línia 38: Línia 38:




{{Gallery
local getArgs = require('Module:Arguments').getArgs
| title        =  
local builder = require("Module:SimpleHTMLBuilder")
| align        =
local p = {}
| footer      =
local root
| style        =
 
| state        =
function p.main(frame)
| height       =
local args = getArgs(frame)
| width       =
return p._main(args)
| perrow      =
end
| mode        =  
 
| whitebg      =  
function p._main(args)
| noborder    =
-- Get width and height from named parameters
| captionstyle =
local width = args['width'] or '100'
| File:
local height = args['height'] or '100'
| Write a caption here
-- Remove width and height from args to avoid processing them as images
| class1=
args['width'] = nil
| alt1=
args['height'] = nil
| File:
| Write a caption here
local gallery = builder.create('div'):addClass('template-gallery')
| class2=
| alt2=
for key, value in pairs(args) do
| File:
if key ~= nil then
| Write a caption here
local content = args[key]
| class3=
local caption = ''
| alt3=
| File:
-- Split content on the delimiter ";" to get the filename and alt text
| Write a caption here
local parts = mw.text.split(content, ';')
| class4=
local filename = parts[1]
| alt4=
if #parts > 1 then
| File:
caption = parts[2]
| Write a caption here
end
| class5=
-- Check if arg is a valid file name
| alt5=
if filename:match('.[^{}<>]+%.%w+') then
}}
content = '[[File:' .. filename .. '|' .. width .. 'x' .. height .. 'px]]'
end
gallery
:tag('div')
:addClass('template-gallery__item')
:tag('div')
:addClass('template-gallery__image')
:cssText('height:' .. height .. 'px')
:cssText('width:' .. width .. 'px')
:wikitext(content)
:done()
:tag('div')
:addClass('template-gallery__caption')
:wikitext(caption)
:done()
:done()
end
end
return gallery:allDone()
end
 
return p

Revisió del 09:24, 10 abr 2025

Què és

Youtube logo.jpeg

En aquesta pàgina expliquem com utilitzar un vídeo de YouTube en aquest wiki. Per fer-ho, s'ha d'accedir al codi d'incrustació que facilita el vídeo, i aquí, hi inserirem el codi.

Com es configura

El primer pas, és accedir a la pàgina del vídeo que volem utilitzar al wiki.

Des del botó "Comparteix" podem veure les opcions per compartir una publicació.

Youtube 1.jpeg


En aquest menú, convé sel·leccionar "Insereix" per accedir al codi d'incrustació.

Youtube 2.jpeg


Quan ens mostri el codi, convé copiar-lo de forma íntegra.

Youtube 3.jpeg

El resultat ha de ser similar a aquest:

<iframe width="560" height="315" src="https://www.youtube.com/embed/xrGCkh8hIe0?si=NKwJ90x7de73K73A" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

Hem d'utilitzar només la part del codi a partir de /embed.

En l'exemple anterior:

/embed/xrGCkh8hIe0?si=HZjtzuI-UpKwY7dm

Copiem el codi exemple i l'enganxem a l'espai indicat amb un guió baix a la estructura:

<iframe key="youtube"path="_"h/>

El resultat final seria:

<iframe key="youtube"path="/embed/xrGCkh8hIe0?si=HZjtzuI-UpKwY7dm"h/>


local getArgs = require('Module:Arguments').getArgs local builder = require("Module:SimpleHTMLBuilder") local p = {} local root

function p.main(frame) local args = getArgs(frame) return p._main(args) end

function p._main(args) -- Get width and height from named parameters local width = args['width'] or '100' local height = args['height'] or '100' -- Remove width and height from args to avoid processing them as images args['width'] = nil args['height'] = nil

local gallery = builder.create('div'):addClass('template-gallery')

for key, value in pairs(args) do if key ~= nil then local content = args[key] local caption =

-- Split content on the delimiter ";" to get the filename and alt text local parts = mw.text.split(content, ';') local filename = parts[1] if #parts > 1 then caption = parts[2] end -- Check if arg is a valid file name if filename:match('.[^{}<>]+%.%w+') then content = '' .. width .. 'x' .. height .. 'px' end

gallery :tag('div') :addClass('template-gallery__item') :tag('div') :addClass('template-gallery__image') :cssText('height:' .. height .. 'px') :cssText('width:' .. width .. 'px') :wikitext(content) :done() :tag('div') :addClass('template-gallery__caption') :wikitext(caption) :done() :done() end end return gallery:allDone() end

return p