gadenbuie / metathis
1

2
#' General Metadata Tags
3
#'
4
#' Generate metadata tags for general website properties.
5
#'
6
#' @template describe-meta
7
#' @param application_name Name of web application (only should be used if the
8
#'   website is used as an app).
9
#' @param theme_color Theme Color for Chrome, Firefox OS and Opera, e.g.
10
#'   `"#00589a"`.
11
#' @param description Short description of the document (limit to 150
12
#'   characters), This content *may* be used as a part of search engine results.
13
#' @param robots Control the behavior of search engine crawling and indexing,
14
#'   e.g. `"index,follow"`. Valid names are `"index"`, `"noindex"`, `"follow"`,
15
#'   `"nofollow"`. May be a vector or a single string with comma-separated
16
#'   values.
17
#'
18
#'   See <https://www.robotstxt.org/meta.html> for more information.
19
#' @param generator Identify the software used to build the document (i.e. -
20
#'   WordPress, Dreamweaver).
21
#' @param subject Short description of your document's subject.
22
#' @param rating Gives a general age rating based on the document's content,
23
#'   e.g. `"General"`.
24
#' @param referrer Allows control over how referrer information is passed, .e.g.
25
#'   `"no-referrer"`. Valid values include `"no-referrer"`,
26
#'   `"no-referrer-when-downgrade"`, `"same-origin"`, `"origin"`,
27
#'   `"strict-origin"`, `"origin-when-cross-origin"`,
28
#'   `"strict-origin-when-cross-origin"`, or `"unsafe-url"`.
29
#'
30
#' @template describe-meta-return
31
#' @examples
32
#' meta() %>%
33
#'   meta_general(
34
#'     application_name = "Application Name",
35
#'     theme_color = "#4285f4",
36
#'     description = "A description of this page",
37
#'     robots = "index,follow",
38
#'     generator = "R-Shiny",
39
#'     subject = "Awesome R projects",
40
#'     rating = "General",
41
#'     referrer = "no-referrer"
42
#'   )
43
#'
44
#' @export
45
meta_general <- function(
46
  .meta = meta(),
47
  application_name = NULL,
48
  theme_color = NULL,
49
  description = NULL,
50
  robots = NULL,
51
  generator = NULL,
52
  subject = NULL,
53
  rating = NULL,
54
  referrer = NULL
55
) {
56 10
  assert_is_meta(.meta)
57

58 10
  general <- list(
59 10
    application_name = application_name,
60 10
    theme_color      = theme_color,
61 10
    description      = description,
62 10
    robots           = robots %??% collapse(robots, ","),
63 10
    generator        = generator,
64 10
    subject          = subject,
65 10
    rating           = rating,
66 10
    referrer         = referrer
67
  )
68

69 10
  meta_general <-
70 10
    general %>%
71 10
    names_replace_underscore("-") %>%
72 10
    collapse_single_string() %>%
73 10
    tag_meta_list()
74

75 10
  append_to_meta(.meta, meta_general)
76
}
77

78

79
#' @rdname meta_general
80
#' @export
81
meta_description <- function(.meta = meta(), description) {
82 10
  meta_general(.meta, description = description)
83
}
84

85
#' @rdname meta_general
86
#' @export
87
meta_subject <- function(.meta = meta(), subject) {
88 10
  meta_general(.meta, subject = subject)
89
}
90

91

92
#' @rdname meta_general
93
#' @export
94
meta_referrer <- function(.meta = meta(), referrer) {
95 10
  meta_general(.meta, referrer = referrer)
96
}
97

98
#' @rdname meta_general
99
#' @export
100
meta_robots <- function(.meta = meta(), robots) {
101 10
  meta_general(.meta, robots = robots)
102
}
103

104
#' @rdname meta_general
105
#' @export
106
meta_theme_color <- function(.meta = meta(), theme_color) {
107 10
  meta_general(.meta, theme_color = theme_color)
108
}

Read our documentation on viewing source code .

Loading