gadenbuie / metathis
1
##
2
## <!-- Disable automatic detection and formatting of possible phone numbers -->
3
## <meta name="format-detection" content="telephone=no">
4
##
5
## <!-- Launch Icon (180x180px or larger) -->
6
## <link rel="apple-touch-icon" href="/path/to/apple-touch-icon.png">
7
##
8
## <!-- Launch Screen Image -->
9
## <link rel="apple-touch-startup-image" href="/path/to/launch.png">
10
##
11
## <!-- Launch Icon Title -->
12
## <meta name="apple-mobile-web-app-title" content="App Title">
13
##
14
## <!-- Enable standalone (full-screen) mode -->
15
## <meta name="apple-mobile-web-app-capable" content="yes">
16
##
17
## <!-- Status bar appearance (has no effect unless standalone mode is enabled) -->
18
## <meta name="apple-mobile-web-app-status-bar-style" content="black">
19
##
20
## <!-- iOS app deep linking -->
21
## <meta name="apple-itunes-app" content="app-id=APP-ID, app-argument=http/url-sample.com">
22
## <link rel="alternate" href="ios-app://APP-ID/http/url-sample.com">
23
##
24
## [Configuring Web Applications](https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html)
25

26

27
#' Apple Web App Meta Tags
28
#'
29
#' @template describe-meta
30
#' @template describe-meta-return
31
#' @param title Launch Icon Title
32
#' @param capable Enables standalone (full-screen) mode if TRUE
33
#' @param status_bar_style Status bar appearance. has no effect unless
34
#'   standalone more is enabled (see `capable`).
35
#'
36
#'   "If content is set to default, the status bar appears normal. If set to
37
#'   black, the status bar has a black background. If set to black-translucent,
38
#'   the status bar is black and translucent. If set to default or black, the
39
#'   web content is displayed below the status bar. If set to black-translucent,
40
#'   the web content is displayed on the entire screen, partially obscured by
41
#'   the status bar. The default value is default."
42
#'
43
#' @references
44
#' <https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html>
45
#'
46
#' @examples
47
#' meta() %>%
48
#'   meta_apple_web_app(
49
#'     title = "My Fancy App",
50
#'     capable = TRUE,
51
#'     status_bar_style = "black-translucent"
52
#'   )
53
#' @export
54
meta_apple_web_app <- function(
55
  .meta = meta(),
56
  title = NULL,
57
  capable = NULL,
58
  status_bar_style = c("default", "black", "black-translucent")
59
) {
60 10
  assert_is_meta(.meta)
61

62 10
  apple <- list(
63 10
    title            = title,
64 10
    capable          = capable %??% ifelse(capable[[1]], "yes", "no"),
65 10
    status_bar_style = status_bar_style %??% match.arg(status_bar_style)
66
  )
67

68 10
  names(apple) <- paste0("apple-mobile-web-app-", names(apple))
69

70 10
  meta_apple <-
71 10
    apple %>%
72 10
    names_replace_underscore("-") %>%
73 10
    collapse_single_string() %>%
74 10
    tag_meta_list()
75

76 10
  append_to_meta(.meta, meta_apple)
77
}
78

79
#' Apple Smart Banner Meta Tag
80
#'
81
#' @template describe-meta
82
#' @template describe-meta-return
83
#' @param app_id Apple app ID
84
#' @param affiliate_id Apple affiliate ID
85
#' @param ... Additional name=value pairs.
86
#'
87
#' @section Example:
88
#'
89
#' ```
90
#' # <!-- Smart App Banner -->
91
#' <meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">
92
#' ```
93
#'
94
#' @export
95
meta_apple_itunes_app <- function(
96
  .meta = meta(),
97
  app_id = NULL,
98
  affiliate_id = NULL,
99
  ...
100
) {
101

102 10
  assert_is_meta(.meta)
103

104 10
  args <- c(
105 10
    list(`app-id` = app_id, `affiliate-data` = affiliate_id),
106 10
    list(...)
107
  )
108 10
  args <- purrr::compact(args)
109 10
  if (!length(args)) {
110 10
    return(.meta)
111
  }
112

113 10
  content <- args %>%
114 10
    purrr::imap_chr(~ paste0(.y, "=", .x)) %>%
115 10
    collapse(",")
116

117 10
  meta_new <- tag_meta(name = "apple-itunes-app", content = content)
118

119 10
  append_to_meta(.meta, list(meta_new))
120
}

Read our documentation on viewing source code .

Loading