-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df68d37
commit 867e2e0
Showing
4 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
project: | ||
type: website | ||
pre-render: pre-render-listing-content.R | ||
preview: | ||
port: 4200 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
--- | ||
title: "Content" | ||
listing: | ||
- id: content | ||
contents: "{talks,teaching}/{pt,es,en}/*/index.qmd" | ||
- id: content-future | ||
contents: | ||
- content_data_futura.yaml | ||
type: grid | ||
fields: [image, date, title, subtitle] | ||
sort: "date desc" | ||
categories: false | ||
sort-ui: true | ||
filter-ui: true | ||
page-size: 100 | ||
|
||
page-size: 100 | ||
- id: content-past | ||
contents: | ||
- content_data_passado.yaml | ||
type: grid | ||
fields: [image, date, title, subtitle] | ||
sort: "date desc" | ||
categories: false | ||
sort-ui: true | ||
filter-ui: true | ||
page-size: 100 | ||
page-layout: full | ||
title-block-banner: false | ||
comments: false | ||
toc: false | ||
toc: true | ||
--- | ||
|
||
Presentations, workshops, and other content. | ||
|
||
For invitations, please email me at: [email protected] | ||
For invitations, please email me at: <[email protected]> | ||
|
||
## Future content | ||
::: {#content-future} | ||
::: | ||
|
||
::: {#content} | ||
## Past content | ||
::: {#content-past} | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
read_yaml_matter <- function(file){ | ||
# Ler o texto do arquivo | ||
input_lines <- readLines(file) | ||
# Encontrar os delimitadores | ||
delimiters <- grep("^---\\s*$", input_lines) | ||
# Extrair as linhas do yaml | ||
yaml_lines <- input_lines[(delimiters[1]+1):(delimiters[2]-1)] | ||
yaml_lines <- yaml_lines[yaml_lines != ""] | ||
yaml_lines <- paste0(yaml_lines, collapse = "\n") | ||
|
||
# Convertendo o yaml para lista | ||
yaml_list <- yaml::yaml.load(yaml_lines) | ||
|
||
# Convertendo a data | ||
yaml_list$data <- as.Date(yaml_list$date) | ||
|
||
# Verificando se a data é futura | ||
yaml_list$data_futura <- yaml_list$data > Sys.Date() | ||
|
||
# Adicionando o caminho do arquivo na lista | ||
yaml_list$path <- file | ||
|
||
# Retornando o yaml | ||
yaml_list | ||
} | ||
|
||
|
||
|
||
preparar_yaml_para_salvar <- function(elemento_lista_yaml){ | ||
# Selecionando apenas os elementos necessários | ||
yaml_selecionado <- list( | ||
title = elemento_lista_yaml$title, | ||
author = elemento_lista_yaml$author, | ||
date = elemento_lista_yaml$date, | ||
path = elemento_lista_yaml$path#, | ||
#categories = elemento_lista_yaml$categories | ||
) | ||
# Retornando o yaml | ||
yaml_selecionado | ||
|
||
} | ||
|
||
|
||
|
||
|
||
criar_arquivo_yaml_data <- function(lista_yaml_data, tipo = "futura"){ | ||
# Criando o arquivo | ||
arquivo <- fs::path(paste0("content_data_", tipo, ".yaml")) | ||
|
||
lista_preparada <- lista_yaml_data |> | ||
purrr::map(preparar_yaml_para_salvar) |> | ||
unname() | ||
|
||
|
||
# Convertendo a lista para yaml | ||
yaml::write_yaml(lista_preparada, arquivo) | ||
|
||
} | ||
|
||
|
||
prepare_file_listing_content <- function(){ | ||
# listando arquivos | ||
qmd_files_talks <- fs::dir_ls(path = "talks", glob = "*.qmd", recurse = TRUE) | ||
qmd_files_teaching <- fs::dir_ls(path = "teaching", glob = "*.qmd", recurse = TRUE) | ||
qmd_files <- c(qmd_files_talks, qmd_files_teaching) | ||
|
||
|
||
# lendo yaml dos arquivos e buscando a data | ||
lista_yaml_qmd <- qmd_files |> | ||
purrr::map(read_yaml_matter) | ||
|
||
# removendo itens sem data | ||
lista_yaml_qmd_com_data <- lista_yaml_qmd |> | ||
purrr::discard(~length(.x$data_futura) == 0) | ||
|
||
|
||
# identificando o conteúdo futuro | ||
lista_yaml_data_futura <- lista_yaml_qmd_com_data |> | ||
purrr::keep(~.x$data_futura) | ||
|
||
# identificando o conteúdo do passado | ||
lista_yaml_data_passado <- lista_yaml_qmd_com_data |> | ||
purrr::discard(~.x$data_futura) | ||
|
||
# Criando os arquivos auxiliares | ||
criar_arquivo_yaml_data(lista_yaml_data_futura, tipo = "futura") | ||
criar_arquivo_yaml_data(lista_yaml_data_passado, tipo = "passado") | ||
|
||
} | ||
|
||
# run functions | ||
prepare_file_listing_content() |