Title: | Convert a 'blogdown' Blog to Quarto |
---|---|
Description: | Takes the folder stucture and files of an old 'blogdown' blog and translates them to what's needed for a Quarto blog. Built for my own personal blog, so your mileage may vary. |
Authors: | Matt Dray [aut, cre] |
Maintainer: | Matt Dray <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-11-15 04:21:28 UTC |
Source: | https://github.com/matt-dray/bd2q |
A convenience function that creates a Quarto blog template and transfers the structure and content of posts and resources from a 'blogdown' blog project.
create_and_transfer( bd_path, q_path, rproj = TRUE, resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), overwrite = FALSE )
create_and_transfer( bd_path, q_path, rproj = TRUE, resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), overwrite = FALSE )
bd_path |
Character. Path to directory containing a 'blogdown' blog from where you want to copy posts |
q_path |
Character. Path to directory containing a Quarto blog where you want to copy posts to. |
rproj |
Logical. Include an R Project (.Rproj) file? Defaults to
|
resources_dir |
Character. The name of the folder that contains resources, such as images, that are used in posts. |
exts_keep |
Character. A vector of extensions for files to keep from the 'blogdown' blog. |
overwrite |
Logical. Overwrite the existing directory and all posts and
resource files at the provided q_path? Defaults to |
Executes create_template, transfer_posts and transfer_resources to set up the basic Quarto blog template and generate and fill the posts/ directory based on the posts found in the provided 'blogdown' blog project
Nothing. New directory structure and files are created at the path given by q_path.
## Not run: create_and_transfer
## Not run: create_and_transfer
Create template structure and files for a basic Quarto blog.
create_template(path, rproj = TRUE, overwrite = FALSE)
create_template(path, rproj = TRUE, overwrite = FALSE)
path |
Character. Path to a directory where you want to create a Quarto blog. |
rproj |
Logical. Include an R Project (.Rproj) file? Defaults to
|
overwrite |
Logical. Overwrite an existing directory at the provided
path? Defaults to |
Creates a blog directory at the user-specified path, with the files _quarto.yml, about.qmd, index.qmd, posts/_metadata.yml, styles.css and an optional .Rproj file. This is similar to the starter blog created in the Quarto quickstart guide, but with some opinionated differences.
Nothing. New directory structure and files are created at the path provided by the user.
## Not run: create_template("~/Documents/new-quarto-project")
## Not run: create_template("~/Documents/new-quarto-project")
Search each Quarto blog post's index.qmd file for lines that contain a supplied regular expression, delete them and overwrite the original file.
remove_line(q_path, detect_rx)
remove_line(q_path, detect_rx)
q_path |
Character. Path to directory containing the Quarto blog. |
detect_rx |
Character. A regular expression that captures text within a line that you want to delete from each post's index.qmd file. |
Nothing. Quarto files are overwritten if they contain matching lines.
## Not run: remove_line( q_path = "~/Documents/new-quarto-project/", detect_rx = "^draft:" # remove YAML line that specifies draft status ) ## End(Not run)
## Not run: remove_line( q_path = "~/Documents/new-quarto-project/", detect_rx = "^draft:" # remove YAML line that specifies draft status ) ## End(Not run)
Replace or Remove Lines from a Post
replace_lines(q_path, match_str, replacement_str, collapse_str = "///")
replace_lines(q_path, match_str, replacement_str, collapse_str = "///")
q_path |
Character. Path to directory containing the Quarto blog. |
match_str |
Character. A vector of strings that match exactly to
consecutive lines in a blog post that you want to replace (with
'replacement_str') or remove (when 'replacement_str' is |
replacement_str |
Character. A vector of consecutive strings to replace
the strings proviede in 'match_str'. Specify |
collapse_str |
Character. The function works by collapsing a post's lines to a single string, with elements separated by some unique string. |
Nothing. Quarto files are overwritten if they contain matching lines.
## Not run: replace_lines( q_path = "~/Documents/new-quarto-project/", match_str = c("This is an example", "These are consecutive lines to match"), replacement_str = c("Replace with this line", "And this one") ) ## End(Not run)
## Not run: replace_lines( q_path = "~/Documents/new-quarto-project/", match_str = c("This is an example", "These are consecutive lines to match"), replacement_str = c("Replace with this line", "And this one") ) ## End(Not run)
Generate the folder structure required to move R Markdown (.Rmd) posts from a 'blogdown' project to a Quarto project and then copy them over, naming each one 'index.qmd' in its own folder.
transfer_posts(bd_path, q_path, ...)
transfer_posts(bd_path, q_path, ...)
bd_path |
Character. Path to directory containing a 'blogdown' blog from where you want to copy posts |
q_path |
Character. Path to directory containing a Quarto blog where you want to copy posts to. |
... |
Passed to fs::file_copy, with the intention that you can supply
|
Assumes that Rmd posts in the 'blogdown' blog are at the path /content/post/YYYY-MM-DD-post-name.Rmd. For Quarto, the corresponding path will be /posts/YYYY-MM-DD-post-name/ and the file containing each post will be named index.qmd. (Each of these individual post directories can also hold a folder of associated resources for each post, which can be generated and copied from a 'blogdown' blog project using the transfer_resources function.)
Nothing. New directory structure and files are created at the path given by q_path.
## Not run: transfer_posts( bd_path = "~/Documents/old-blogdown-project/", q_path = "~/Documents/new-quarto-project/", overwrite = TRUE ) ## End(Not run)
## Not run: transfer_posts( bd_path = "~/Documents/old-blogdown-project/", q_path = "~/Documents/new-quarto-project/", overwrite = TRUE ) ## End(Not run)
Copy resources (images, audio files, etc) from the directory structure of a 'blogdown' blog to that required by Quarto. Assumes you've already set up the directory structure for each post using transfer_posts.
transfer_resources( bd_path, q_path, resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), ... )
transfer_resources( bd_path, q_path, resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), ... )
bd_path |
Character. Path to directory containing a 'blogdown' blog from where you want to copy resources. |
q_path |
Character. Path to directory containing a Quarto blog where you want to copy resources to. |
resources_dir |
Character. The name of the folder that contains resources, such as images, that are used in posts. |
exts_keep |
Character. A vector of extensions for files to keep from the 'blogdown' blog. |
... |
Passed to fs::file_copy, with the intention that you can supply
|
Assumes that the resources for a given 'blogdown' post are at the path /static/post/YYYY-MM-DD-post-name_files/, and the that the corresponding Quarto project will have a subdirectory for resources, which defaults to the name 'resources/', in the folder /posts/YYYY-MM-DD-post-name/ alongside that post's index.qmd file.
Nothing. New directory structure and files are created at the path given by q_path, in the subdirectory given by resources_dir.
## Not run: transfer_resources( bd_path = "~/Documents/old-blogdown-project/", q_path = "~/Documents/new-quarto-project/", resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), overwrite = TRUE ) ## End(Not run)
## Not run: transfer_resources( bd_path = "~/Documents/old-blogdown-project/", q_path = "~/Documents/new-quarto-project/", resources_dir = "resources", exts_keep = c("gif", "jpg", "jpeg", "png", "svg", "wav"), overwrite = TRUE ) ## End(Not run)
Find lines from each post that contain paths to resources and update them from 'blogdown' to Quarto structure.
update_resource_paths( q_path, resources_dir = "resources", resource_rx = "<img src=" )
update_resource_paths( q_path, resources_dir = "resources", resource_rx = "<img src=" )
q_path |
Character. Path to directory containing the Quarto blog. |
resources_dir |
Character. The name of the folder that contains resources, such as images, that are used in posts. |
resource_rx |
Character. A regular expression that will capture a line from a qmd file that contains resource paths to be edited. |
Assumes that the resources for a 'blogdown' post are at the path /static/post/YYYY-MM-DD-post-name_files/, while for Quarto there's a subdirectory for resources (defaults to 'resources/) in /posts/YYYY-MM-DD-post-name/ alongside that post's index.qmd file.
Nothing. New directory structure and files are created at the path given by q_path, in the subdirectory given by resources_dir.
## Not run: update_resource_paths( q_path = "~/Documents/new-quarto-project/", resources_dir = "resources", resource_rx = "<img src=" # lines that contain images ) ## End(Not run)
## Not run: update_resource_paths( q_path = "~/Documents/new-quarto-project/", resources_dir = "resources", resource_rx = "<img src=" # lines that contain images ) ## End(Not run)