http_get( $this->origin() . '/', 'GET / (Accept: text/markdown)', $evidence, array( 'headers' => array( 'Accept' => 'text/markdown' ) ) ); if ( '' !== $res['error'] && 0 === $res['code'] ) { return $this->unable( 'Could not reach the homepage — ' . $res['error'], $evidence ); } $ctype = isset( $res['headers']['content-type'] ) ? $res['headers']['content-type'] : ''; if ( 0 !== stripos( $ctype, 'text/markdown' ) ) { return $this->fail( 'Homepage does not serve Markdown for Accept: text/markdown — enable Markdown Negotiation first', $evidence ); } $body = ltrim( $res['body'] ); $lines = array_slice( preg_split( '/\r\n|\r|\n/', $body ), 0, 40 ); $keys = array(); $ok = false; if ( isset( $lines[0] ) && '---' === trim( $lines[0] ) ) { foreach ( array_slice( $lines, 1 ) as $line ) { if ( '---' === trim( $line ) ) { $ok = true; break; } if ( preg_match( '/^([A-Za-z_][\w-]*)\s*:/', $line, $k ) ) { $keys[] = $k[1]; } } } if ( ! $ok || empty( $keys ) ) { $evidence[] = Evidence::parse( 'Inspect the first lines of the Markdown body', 'negative', 'No `---` … `---` frontmatter block with keys at the top of the document.' ); return $this->fail( 'Markdown body has no frontmatter metadata block', $evidence, array( 'keys' => $keys ) ); } $evidence[] = Evidence::parse( 'Inspect the first lines of the Markdown body', 'positive', 'Frontmatter keys: ' . implode( ', ', $keys ) . '.' ); return $this->pass( 'Markdown body opens with frontmatter (' . implode( ', ', $keys ) . ')', $evidence, array( 'keys' => $keys ) ); } }