Erfahrung mit AMP
Eingetragen von SaarlandToday (264)
am 20.10.2020 - 15:24 Uhr in
am 20.10.2020 - 15:24 Uhr in
Hat einer von euch Erfahrungen mit AMP?
- Anmelden oder Registrieren um Kommentare zu schreiben
Hat einer von euch Erfahrungen mit AMP?
Beiträge im Forum: 249179
Registrierte User: 19885
Neue User:
wla | 9380 |
stBorchert | 6003 |
quiptime | 4972 |
Tobias Bähr | 4019 |
bv | 3924 |
ronald | 3845 |
md | 3717 |
Thoor | 3678 |
Alexander Langer | 3416 |
Exterior | 2903 |
Was möchtest du denn konkret
am 14.12.2020 - 11:38 Uhr
Was möchtest du denn konkret wissen.
Grundsätzlich würdest du für AMP ein neues Theme anlegen, welches deine Inhalt dann entsprechend der AMP Spezifikation entsprechend ausgibt.
Um das Ganze in Drupal umzusetzen, kannst du das AMP Modul nutzen. Alles Weitere ergibt sich dann eigentlich aus Modul/ AMP Dokumentation.
Wichtig ist hier natürlich immer auf eine valide Ausgabe zu prüfen - dabei ist zu beachten, dass AMP nicht alle HTML Tags unterstützt und bspw. die Einbdung von Third Party Dingen so direkt nicht möglicht ist. Aber dazu finden sich in der Dokumentation sehr viele Beispiele.
http://www.twitter.com/_steffenr
Drupal-Initiative e.V.
Danke für den Tip. Ich habe
am 15.12.2020 - 15:13 Uhr
Danke für den Tip.
Ich habe da nur ein kleines Verständnisproblem.
Wie merkt das System das es von einem Mobilen Gerät aufgreufen wird, bzw. wie geht es vonstatten das auf einem Mobilen Gerät das andere Template angezeigt wird?
Egal wie der Weg auch sein mag, Hauptsache das Ergebnis stimmt.
Amp Seiten haben aus der
am 17.12.2020 - 02:39 Uhr
Das System merkt nicht, ob da ein mobiles Gerät abfragt oder nicht. Zumindest nicht an der Stelle. Das merkt die Suchmaschine bei der Anfrage durch den Nutzer. Aber fangen wir mal anders an:
Amp Seiten haben aus der Amp-Spezifikation heraus sozusagen eine bestimmte Dateiendung.
Das Modul muss also mittels Php nachsehen, ob nun eine .amp-Version der Seite vorliegt oder nicht und im Falle einer entsprechenden Anfrage den Nutzer auf die richtige Seite Weiterleiten.
Z. B. So:
<?php
namespace Drupal\amp\Routing;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Theme\ThemeManager;
use Symfony\Component\Routing\Route;
use Drupal\amp\EntityTypeInfo;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\AdminContext;
/**
* Provides a helper class to determine whether the route is an amp one.
*/
class AmpContext extends ServiceProviderBase {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Theme manager.
*
* @var \Drupal\Core\Theme\ThemeManager
*/
protected $themeManager;
/**
* Information about AMP-enabled content types.
*
* @var \Drupal\amp\EntityTypeInfo
*/
protected $entityTypeInfo;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The admin context.
*
* @var \Drupal\Core\Routing\AdminContext
*/
protected $adminContext;
/**
* Construct a new amp context helper instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
* @param \Drupal\Core\Theme\ThemeManager $themeManager
* The theme manager.
* @param \Drupal\amp\EntityTypeInfo $entity_type_info
* Information about AMP-enabled content types.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Routing\AdminContext $adminContext
* The admin route context.
*/
public function __construct(ConfigFactoryInterface $configFactory, ThemeManager $themeManager, EntityTypeInfo $entityTypeInfo, RouteMatchInterface $routeMatch, AdminContext $adminContext) {
$this->configFactory = $configFactory;
$this->themeManager = $themeManager;
$this->entityTypeInfo = $entityTypeInfo;
$this->routeMatch = $routeMatch;
$this->adminContext = $adminContext;
}
/**
* Determines whether the active route is an AMP route.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param mixed $entity
* The entity to assess, if any.
* @param boolean $checkTheme
* Whether or not to check the active theme as a part of the test.
*
* @return bool
* Returns TRUE if the route is an AMP route, otherwise FALSE.
*/
public function isAmpRoute(RouteMatchInterface $routeMatch = NULL, $entity = NULL, $checkTheme = TRUE) {
if (!$routeMatch) {
$routeMatch = $this->routeMatch;
}
// Some routes cannot be AMP.
if ($route_is_not_amp = $this->routeIsNotAmp($routeMatch)) {
return FALSE;
}
// Some routes must be AMP.
if ($route_is_amp = $this->routeIsAmp($routeMatch)) {
return TRUE;
}
// If we have an entity, we can test it.
$route_entity = $this->routeEntity($routeMatch);
if ($entity instanceof \Drupal\node\NodeInterface || $route_entity instanceof \Drupal\node\NodeInterface) {
$entity_is_amp = $this->entityIsAmp($entity);
$route_entity_is_amp = $this->entityIsAmp($route_entity);
return $entity_is_amp || $route_entity_is_amp;
}
// Otherwise, check the active theme.
if ($checkTheme) {
return $this->routeThemeisAmp($routeMatch);
}
return FALSE;
}
/**
* See if this route uses the AMP theme.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return boolean
*/
public function routeThemeisAmp(RouteMatchInterface $routeMatch) {
$current_theme = $this->themeManager->getActiveTheme($routeMatch)->getName();
$amp_theme = $this->configFactory->get('amp.theme')->get('amptheme');
if ($amp_theme == $current_theme) {
return TRUE;
}
return FALSE;
}
/**
* Definitely an AMP route?
*
* Some routes must be AMP.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return boolean
*/
public function routeIsAmp(RouteMatchInterface $routeMatch) {
$route = $routeMatch->getRouteObject();
if (!$route instanceof Route) {
return FALSE;
}
// Check if the globally-defined AMP status has been changed to TRUE (it
// is FALSE by default).
if ($route->getOption('_amp_route')) {
return TRUE;
}
return FALSE;
}
/**
* Not an AMP route?
*
* Check off things that indicate this can't be an AMP route. TRUE means it
* can't be an AMP route, FALSE means we can't tell.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return boolean
*/
public function routeIsNotAmp(RouteMatchInterface $routeMatch) {
// Is this an admin route?
if ($this->adminContext->isAdminRoute()) {
return TRUE;
}
// Only path with amp in the query string or amp _wrapper_format, unless all pages are AMP.
$everywhere = $this->configFactory->get('amp.settings')->get('amp_everywhere');
$amp_wrapper_format = isset($_GET['_wrapper_format']) && $_GET['_wrapper_format'] == 'amp';
$amp = isset($_GET['amp']);
if (!$everywhere && !$amp_wrapper_format && !$amp) {
return TRUE;
}
return FALSE;
}
/**
* Get the entity from the route.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return mixed
* Either an entity or FALSE.
*/
public function routeEntity(RouteMatchInterface $routeMatch) {
if ($node = $routeMatch->getParameter('node')) {
return $node;
}
return FALSE;
}
/**
* See if this entity is AMP.
*
* @param mixed $entity
* An entity
*
* @return boolean
*/
public function entityIsAmp($entity) {
if ($entity instanceof \Drupal\node\NodeInterface) {
$type = $entity->getType();
return $this->entityTypeInfo->isAmpEnabledType($type);
}
return FALSE;
}
}
?>
Na ja und wenn diese Diagnose abgeschlossen ist und feststeht, dass eine Amp-Variante vorhanden ist, wird halt das entsprechende Twig-Template in gerenderter Form an den anfragenden Client gesendet.
Grundsätzlich mit einem ähnlichen Ansatz, wie dem, mit dem Drupal entscheidet, ob es gerade das Feontend-Theme oder das Theme für den Verwaltungsbereich anzeigen soll.
Noch einfacher ausgedgdrückt:
Es gibt in der Datenbank eine Tabelle.
Das Modul sieht in einer Spalte dieser Tabelle nach einem Wert
1=Amp-Version vorhanden
0=Keine Amp-Version vorhanden.
Ist der Wert 1 wird das Amp-Theme zusammen mit dem Amp-HTML an den Browser/Bot/Client usw. zur Anzeige übergeben
Ist der Wert 0 wird die normale Seite geladen.
So: Zweiter Teil der Frage:
Ist eine Amp-Version der Seite vorhanden und der Google-Bot hat sie gefunden und ruft diese genauso ab, wie sie dir angezeigt würde wenn du eine .amp-Datei im Browser aufrufen würdest.
Diese Ausgabe nimmt der Bot mit und legt eine komprimierte Kopue der Seite in den ampcache auf den Google-Servern. Also eigentlich schickt der Bot ein anderes Programm auf deine Website, dass den Cofe abholen kommt, aber ich schweife ab. Zusammen mit einer Infornation darüber, wo sich das originale .amp-Dokument im Internet befindet und welche URL die dazugehörige echte Seite hat.
Diese Infos wandern wieder in eine Tabelle oder besser eine .json-Datei
Wenn das nächste mal jemand deine Seite mit dem Handy bei Google sucht bekommt er über den Link auf der Ergebnisseite unter bestimmten Bedingungen. Z. B. langsames Internet, wegen schlechter Netzabdeckung, statt den Link zur Original-Website den Link zur von Google zwischengespeicherten Version der Seite ausgeliefert. Statt seiner Seite wirdxann also amp.google.com/xxx aufgerufen.
Das kann man jetzt noch ungefähr eine Stunde lang so weiter thematisieren und dann hat man den nächsten Vortrag fürs nächste Online-Meeting fertig.
Ich frag jetzt einfach mal ganz dreist:
Warum willst du das denn überhaupt wissen?
Schließlich ist das wissen über Amp genauso unnötig, wie zu wissen, dass in Reykjavík das Telefonbuch nach Vornamen sortiert ist. Die Hauptsache ist doch, dass es funktioniert. Ich warte mal auf die sich aus deiner Antwort ergebende Anschlussfrage.
https://drupal-tv.de
Drupal sehen und lernen